Olá, estou tentando abrir uma janela dentro de um JPanel.
Principal
package View;
public class Principal extends javax.swing.JFrame {
/** Creates new form Principal */
public Principal() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
painel = new javax.swing.JPanel();
jMenuBar1 = new javax.swing.JMenuBar();
jmenu_arquivo = new javax.swing.JMenu();
jmenuitem_novo = new javax.swing.JMenuItem();
jmenuitem_sair = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout painelLayout = new javax.swing.GroupLayout(painel);
painel.setLayout(painelLayout);
painelLayout.setHorizontalGroup(
painelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 626, Short.MAX_VALUE)
);
painelLayout.setVerticalGroup(
painelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 498, Short.MAX_VALUE)
);
jmenu_arquivo.setText("Arquivo");
jmenuitem_novo.setText("Novo");
jmenuitem_novo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jmenuitem_novoActionPerformed(evt);
}
});
jmenu_arquivo.add(jmenuitem_novo);
jmenuitem_sair.setText("Sair");
jmenu_arquivo.add(jmenuitem_sair);
jMenuBar1.add(jmenu_arquivo);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(painel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(painel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jmenuitem_novoActionPerformed(java.awt.event.ActionEvent evt) {
Cadastro obj_form = new Cadastro();
painel.add(obj_form);
obj_form.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Principal().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenu jmenu_arquivo;
private javax.swing.JMenuItem jmenuitem_novo;
private javax.swing.JMenuItem jmenuitem_sair;
private javax.swing.JPanel painel;
// End of variables declaration
}
Cadastro.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Cadastro.java
*
* Created on 19/10/2010, 19:43:33
*/
package View;
/**
*
* @author Mauro
*/
public class Cadastro extends javax.swing.JPanel {
/** Creates new form Cadastro */
public Cadastro() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jInternalFrame1 = new javax.swing.JInternalFrame();
jInternalFrame1.setVisible(true);
javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
jInternalFrame1Layout.setHorizontalGroup(
jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 394, Short.MAX_VALUE)
);
jInternalFrame1Layout.setVerticalGroup(
jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 274, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jInternalFrame1)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jInternalFrame1)
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JInternalFrame jInternalFrame1;
// End of variables declaration
}