Oi,
estou precisando que um instância de JInternalFrame após ser criada seja usada toda que vez que se queira abrir uma nova instância do mesmo objeto.
Consegui realizar essa operação, mas acredito que possa haver um modo mais direto para o que eu pretendo.
Abaixo os fontes para uma avaliação:
// PrincipalFrame.java
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class PrincipalFrame extends JFrame {
private JMenu menu;
private JMenuItem menuItem1;
private JMenuBar menuBar;
private JDesktopPane desktop;
private Frame_1 frame1;
public PrincipalFrame () {
super("Frame Principal");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setBounds(100,50,650,600);
menuBar = new JMenuBar();
menu = new JMenu("Frames");
menuItem1 = new JMenuItem("Frame 1");
menu.add(menuItem1);
menuBar.add(menu);
this.setJMenuBar(menuBar);
menuItem1.addActionListener(new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
exibeFrame1();
}
}
);
desktop = new JDesktopPane();
this.setContentPane(desktop);
}
public static void main (String args[]) {
new PrincipalFrame().setVisible(true);
}
public void exibeFrame1() {
if ( frame1 == null || // verifica se a instancia nao foi criada ou
(! frame1.isDisplayable() && ! frame1.isIcon() )) { // nao esta "a mostra" e nao esta minimizado
if ( frame1 != null) {
frame1 = null;
}
frame1 = new Frame_1();
desktop.add(frame1);
frame1.setVisible(true);
} else
frame1.alteraLabel();
try {
frame1.setSelected(true);
} catch (PropertyVetoException ex) {
ex.printStackTrace();
}
}
}
// Frame_1.java
import java.awt.Container;
import java.beans.PropertyVetoException;
import javax.swing.JButton;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JInternalFrame;
public class Frame_1 extends JInternalFrame{
private static Integer nrFrame = 1;
private static Integer nrFrame_aux ;
private static Integer nrAlteracoes = 0 ;
private JLabel label;
public Frame_1() {
super("Novo Frame n. " + nrFrame , true, // resizable
true, // closable
true, // maximizable
true);// iconifiabl
Container cont = this.getContentPane();
cont.setLayout(new FlowLayout(FlowLayout.CENTER));
label = new JLabel();
label.setText("Texto no Frame nr. " + nrFrame);
cont.add(label);
nrFrame_aux = nrFrame;
++nrFrame;
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
// this.pack();
this.setSize(400, 400);
}
public void alteraLabel() {
label.setText("Alteracao nr " + ++nrAlteracoes + " no Label do Frame nr. " + nrFrame_aux);
}
}
Nesse exemplo, ao minimizar o frame interno e tentar abrir outra instância, não se outra outro frame, mas também não se maximiza o frame minimizado.
Se puder ajudar, agradeço.

