Back invisible a JPanel and make visible another

0

I have a problem making a panel visible after rendering another panel invisible.

This is my JFrame, which contains a JPanel which in turn contains these 3 JButton as you can see:

So that you have a clearer idea of what I do:

This is the method I use in any of the 3 buttons to make the start disappear and make any other appear.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    panelInicio.setVisible(false);  
    panelPrimalidad.setVisible(true);  
    panelSubconjuntos.setVisible(false);  
    panelKColoreable.setVisible(false);  
}  

The running result is the following after pressing any of the buttons:

And the structure of all my JPanel (different from the Start) is this:

    
asked by Parzival 12.04.2017 в 04:46
source

2 answers

2

I would like to see how you have implemented the other panels, since I am not used to working with visual tools (The tree), but I would say that your other three panels do not have a parent, you should add them to the JFrame and make them invisible immediately.

Something like that ...

jframePadre.add(panelKColoreable);
jframePadre.add(panelSubconjuntos);
jframePadre.add(panelPrimalidad);
panelKColoreable.setVisible(false);
panelSubconjuntos.setVisible(false);
panelPrimalidad.setVisible(false);

If the panels do not have a parent frame, they can not be displayed.

    
answered by 12.04.2017 / 16:29
source
1

How can you try with the following? // Crea tus paneles // Crea tu Jframe // Dentro de la clase Jframe crea un objeto de cada uno de los paneles. ClaseObjetoPanel objetoCreado; //dentro del constructor del frame coloca lo siguiente: public constructor(){ this.setLayout(new FlowLayout()); this.pack(); } // Ahora en el metodo del evento click o action del boton coloca esto public .....action(){ try{ getContentPane().removeAll(); objetoCreado = new ClaseObjetoPanel(); this.add(objetoCreado,BorderLayout.CENTER); this.pack(); maximizar(); }catch(Exception e){ e.printStackTrace(); } } //Creamos el metodo que maximiza el elemento. public void maximizar(){ this.setExtendedState(MAXIMIZED_BOTH); } Greetings .....

    
answered by 12.04.2017 в 20:15