Avoid opening more than one of the same JInternalFrame [duplicate]

1

I'm developing an application that uses JInternalFrame within a JDesktop . When I press the button, this JInternalFrame is instantiated and the window is opened, however, if I press the button again, it will open several different windows. What is the best way to identify this% open% so that when the button is pressed, it will not open another equal?

I tried to use JinternalFrame but did not get any results.

The event that calls the JInternalFrame is this:

private void jButton13MouseClicked(java.awt.event.MouseEvent evt) {
    Fimplantar n = new Fimplantar();
    jDesktopPane1.add(n);
    n.setPosicao();
} 
    
asked by anonymous 02.02.2016 / 17:16

2 answers

0

Save your JInternalFrame as a field of the class that contains this event and make sure it contains something before you create a copy of the frame. Something like this:

public class MeuJDesktop extends JDesktop {

    FImplantar meuJInternalFrame;
    // .....

    private void jButton13MouseClicked(java.awt.event.MouseEvent evt) {

        if (meuJInternalFrame != null) {
            this.meuJInternalFrame = new Fimplantar();
            jDesktopPane1.add(this.meuJInternalFrame);
            this.meuJInternalFrame.setPosicao();
        }

    }

    // .....
}
    
02.02.2016 / 18:28
0

I was able to solve with the code below.

public void actionPerformed(ActionEvent evt){

            if(frameUm == null){
                frameUm = new InternalFrameUm();
                frameUm.setVisible(true);
                desktopPane.add(frameUm);
            }
            else if(!frameUm.isVisible()){
                frameUm.setVisible(true);
                desktopPane.add(frameUm);
            }
        }
    
02.02.2016 / 20:27