Avoid opening more than one of the same Jinternalframe

Asked

Viewed 797 times

1

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

I tried to use isvisible() but I didn’t 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();
} 

2 answers

0

I managed 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);
            }
        }

0

Keep one of your JInternalFrame as a class field containing this event and check if it contains something before creating a frame copy. Something like that:

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();
        }

    }

    // .....
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.