import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
@SuppressWarnings("serial")
public class painelFrame extends javax.swing.JFrame {
public painelFrame(){
initComponents();
setLocationRelativeTo(null);
setExtendedState(painelFrame.MAXIMIZED_BOTH);
setTitle("Fox Home Vídeo");
}
private void initComponents() {
JFrame frame = new javax.swing.JFrame();
JMenuBar barra = new javax.swing.JMenuBar();
frame.add(barra);
JMenu cliente = new javax.swing.JMenu("Cadastro");
barra.add(cliente);
JDesktopPane lc = new javax.swing.JDesktopPane();
lc.add(frame);
}
public static void main(String [] args){
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new painelFrame().setVisible(true);
}
});
}
}
o que faltar implementar, para que o menu possa ser visto???
Não é frame.add(barra), mas sim frame.setJMenuBar(barra)
[]´s
Ah, outra coisa. Não é assim que se usa um JDesktopPane.
Um JDesktopPane deve estar dentro de um JFrame, e então vc usa JInternalFrames no JDesktopPane.
http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html
[]´s
[quote=davidbuzatto]Não é frame.add(barra), mas sim frame.setMenuBar(barra)
[]´s[/quote]
bem, fiz como vc disse, mais ainda assim não aparece!!!
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
@SuppressWarnings("serial")
public class painelFrame extends javax.swing.JFrame {
public painelFrame(){
initComponents();
setLocationRelativeTo(null);
setExtendedState(painelFrame.MAXIMIZED_BOTH);
setTitle("Fox Home Vídeo");
}
private void initComponents() {
JFrame frame = new javax.swing.JFrame();
JMenuBar barra = new javax.swing.JMenuBar();
JMenu cliente = new javax.swing.JMenu("Cadastro");
barra.add(cliente);
frame.setJMenuBar(barra);
JDesktopPane lc = new javax.swing.JDesktopPane();
getContentPane().add(lc);
}
public static void main(String [] args){
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new painelFrame().setVisible(true);
}
});
}
}
qual seria o pequeno erro???
Tentei rodar seu programa e ele dá uma exceção logo de cara. Em vez disso, use uma IDE como o Visual Editor do Eclipse (foi o que usei para o código abaixo) ou o NetBeans.
Para quem prefere fazer layouts à mão, como é meu caso, é melhor usar o Visual Editor. Para quem gosta de drag & drop, o NetBeans é melhor.
package guj;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class TesteJMenuBar extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel pnlContentPane = null;
private JMenuBar mnbMain = null;
private JMenu mnuFile = null;
private JMenuItem mniExit = null;
private JDesktopPane dspMain = null;
private JPanel getPnlContentPane() {
if (pnlContentPane == null) {
pnlContentPane = new JPanel();
pnlContentPane.setLayout(new BorderLayout());
pnlContentPane.add(getDspMain(), BorderLayout.CENTER);
}
return pnlContentPane;
}
private JMenuBar getMnbMain() {
if (mnbMain == null) {
mnbMain = new JMenuBar();
mnbMain.add(getMnuFile());
}
return mnbMain;
}
private JMenu getMnuFile() {
if (mnuFile == null) {
mnuFile = new JMenu();
mnuFile.setText("File");
mnuFile.setMnemonic(KeyEvent.VK_F);
mnuFile.add(getMniExit());
}
return mnuFile;
}
private JMenuItem getMniExit() {
if (mniExit == null) {
mniExit = new JMenuItem();
mniExit.setText("Exit");
mniExit.setMnemonic(KeyEvent.VK_X);
mniExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
TesteJMenuBar.this.dispose();
}
});
}
return mniExit;
}
private JDesktopPane getDspMain() {
if (dspMain == null) {
dspMain = new JDesktopPane();
}
return dspMain;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TesteJMenuBar thisClass = new TesteJMenuBar();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public TesteJMenuBar() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setJMenuBar(getMnbMain());
this.setContentPane(getPnlContentPane());
this.setTitle("Teste JMenuBar");
}
}

Vc ta percebendo o que ta fazendo? Vc ta instanciando um frame dentro de outro.
Nunca vai funcionar mesmo.
Outra coisa. Vc dá import de tudo, e no código fica usando o caminh completo da classe…
Mais uma: nome de classe começa com letra maiúscula (convensão).
Mais uma: faltou a operação de fechamento do frame.
Olha o código corrigido:
[code]import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
public class PainelFrame extends JFrame {
public PainelFrame() {
initComponents();
setLocationRelativeTo( null );
setExtendedState( JFrame.MAXIMIZED_BOTH );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setTitle( "Fox Home Vídeo" );
}
private void initComponents() {
JMenuBar barra = new JMenuBar();
JMenu cliente = new JMenu( "Cadastro" );
barra.add( cliente );
setJMenuBar( barra );
JDesktopPane lc = new javax.swing.JDesktopPane();
add( lc );
}
public static void main( String[] args ) {
java.awt.EventQueue.invokeLater( new Runnable() {
public void run() {
new PainelFrame().setVisible( true );
}
} );
}
}[/code]
[quote=davidbuzatto]Vc ta percebendo o que ta fazendo? Vc ta instanciando um frame dentro de outro.
Nunca vai funcionar mesmo.
Outra coisa. Vc dá import de tudo, e no código fica usando o caminh completo da classe…
Mais uma: nome de classe começa com letra maiúscula (convensão).
Mais uma: faltou a operação de fechamento do frame.
Olha o código corrigido:
[code]import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
public class PainelFrame extends JFrame {
public PainelFrame() {
initComponents();
setLocationRelativeTo( null );
setExtendedState( JFrame.MAXIMIZED_BOTH );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setTitle( "Fox Home Vídeo" );
}
private void initComponents() {
JMenuBar barra = new JMenuBar();
JMenu cliente = new JMenu( "Cadastro" );
barra.add( cliente );
setJMenuBar( barra );
JDesktopPane lc = new javax.swing.JDesktopPane();
add( lc );
}
public static void main( String[] args ) {
java.awt.EventQueue.invokeLater( new Runnable() {
public void run() {
new PainelFrame().setVisible( true );
}
} );
}
}[/code][/quote]
vlw, agora deu certo!!!
Obrigado pela atenção!