ola,
segue um exemplo vê se te serve, adiciona mais a classe que rafael criou e te diverte ai.
1 -- JFrame Principal
=============================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* PrincipalJFrame.java
*
* Created on Mar 16, 2011, 2:00:48 PM
*/
package teste;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
/**
*
* @author Jailes
*/
public class PrincipalJFrame extends javax.swing.JFrame {
//Referencia para objeto singleton
//Para pode pega a instancia e add internalframes
private static PrincipalJFrame instance = null;
public static PrincipalJFrame getInstance(){
if(instance == null){
instance = new PrincipalJFrame();
}
return instance;
}
/** Creates new form PrincipalJFrame */
public PrincipalJFrame() {
initComponents();
iniciaPrimeiroJIF();
}
private void iniciaPrimeiroJIF(){
PrimeiroJInternalFrame pjif = new PrimeiroJInternalFrame();
pjif.setVisible(true);
addInternalFrame(pjif);
}
//Metodo que ira adiciona internal frame no jdeskpane
public void addInternalFrame(JInternalFrame jit){
try {
jDesktopPane.add(jit);
jit.setSelected(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(PrincipalJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
/** 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() {
jDesktopPane = new javax.swing.JDesktopPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("JFrame Principal");
jDesktopPane.setPreferredSize(new java.awt.Dimension(500, 400));
getContentPane().add(jDesktopPane, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
instance = new PrincipalJFrame();
instance.setVisible(true);
}
});
}
// Variables declaration - do not modify
// JDesk a onde sera adicionados JInternalFRame
private javax.swing.JDesktopPane jDesktopPane;
// End of variables declaration
}
2 -- Primeiro JInternal Frame
==========================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* PrimeiroJInternalFrame.java
*
* Created on Mar 16, 2011, 2:01:19 PM
*/
package teste;
/**
*
* @author Jailes
*/
public class PrimeiroJInternalFrame extends javax.swing.JInternalFrame {
/** Creates new form PrimeiroJInternalFrame */
public PrimeiroJInternalFrame() {
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() {
jButton1 = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Primeiro JInternalFrame");
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(303, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(18, 18, 18))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(244, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
SegundoJInternalFrame sjif = new SegundoJInternalFrame();
sjif.setVisible(true);
PrincipalJFrame.getInstance().addInternalFrame(sjif);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
3 -- Segundo JInternal Frame
===============================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SegundoJInternalFrame.java
*
* Created on Mar 16, 2011, 2:01:36 PM
*/
package teste;
/**
*
* @author Jailes
*/
public class SegundoJInternalFrame extends javax.swing.JInternalFrame {
/** Creates new form SegundoJInternalFrame */
public SegundoJInternalFrame() {
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() {
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Segundo JInternalFrame");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 394, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 278, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
// Variables declaration - do not modify
// End of variables declaration
}
At+,
Jailes