JDialogs are repeated

1

I am developing an application in which I call several JInternalFrame from a menu. These JInternalFrames open a JDialog in turn.
The problem arises when I open for second, third and so on said frames, because when calling the dialogs, they open as many times as previously opened the frame. That is to say, if I open it for the first time, when calling the dialog it is normally displayed. If I open it a second time, the JInternalFrame runs normally, but the dialog opens twice, then three times, and so on.
The code I use to call the JInternalFrame is the following:

public void abrir_vtClientes(){
  vtCliente v = new vtCliente();
  boolean mostrar=true;
  for (int a=0;a<dsk.getComponentCount();a++){     // verificar si es instancia de algun componente que ya este en el jdesktoppane
    if( v.getClass().isInstance( dsk.getComponent(a) )){
       mostrar=false; 
    }
  }
  if(mostrar){
    vtCliente.rbAlumnos.setSelected(true);
    dsk.add(v);
     v.setSize(800,600);
  }
  v.show();  
}

And the call to jdialog is this:

dlgCliente.setSize(900,400);
dlgCliente.setModal(true);
dlgCliente.setVisible(true);

Thanks in advance for the help given

    
asked by Jack Ryan 06.09.2016 в 15:41
source

1 answer

1

Investigating a little I solved my doubt. I hang here the code just in case it is useful. The first thing I did was to call the windows from a class (Controller) on my desk, as follows:

public class dskTop {

     private static vtCliente cli;



public static void abrir_vtClientes(JDesktopPane desk){
    if(cli != null && !cli.isShowing()){
        cli.show();
        desk.remove(cli);
        try{
            desk.add(cli, JLayeredPane.DEFAULT_LAYER); 
        }catch(IllegalArgumentException ex){               
            desk.add(cli, JLayeredPane.DEFAULT_LAYER);                
        }  
    }
    if(cli == null)
    {
      cli = new vtCliente();
      cli.rbAlumnos.setSelected(true);
      desk.add(cli, JLayeredPane.DEFAULT_LAYER);
    } 
   activarVentana(desk,cli);
}

And this is the activateVentana () method that is located in the same class

private static void activarVentana(JDesktopPane desk,JInternalFrame vnt)
{
    try {
        vnt.setSelected(true);
    } catch (PropertyVetoException ex) {
        Logger.getLogger(dskTop.class.getName()).log(Level.SEVERE, null, ex);
    }
    desk.setPosition(vnt, 0);
}
}//fin de la clase dskTop

Then from the desktop window, the menu item that calls my window was programmed with the following code:

private void mniClienteActionPerformed(java.awt.event.ActionEvent evt) {                                           
    dskTop.abrir_vtClientes(dsk);//Donde dsk es el nombre de la variable JDesktopPane
}

This way the application worked perfectly. I hope to be of help to those who have a situation like mine. Greetings.

    
answered by 06.09.2016 в 22:31