Mohammed Housseyn Taleb
Mohammed Housseyn Taleb

Reputation: 1828

How to show a specific panel in another using a method call?

I m using java under netbeans IDE, I created a JFrame that contains two panel the first contains a button the second is empty

I also created a JPanel file that contains some text fields and labels I want to create a method which will display the JPanel file in the empty panel in the JFrame

My code as below :

 public class jpanelTools{

   public static final void ShowPanel(JPanel target, JPanel object){

    target.add(object, new GridBagConstraints());
    target.invalidate();
    target.revalidate();
    target.validate();
    target.repaint();
    target.show();
    object.validate();
    object.repaint();
    object.show();

    }
}

My JFrame Button ActionPerformed Code :

         jpanelTools.ShowPanel(emptyPanel,new DesignedPanel());

the image shows my project : enter image description here

nothing happens when I run the JFRAME .

Please Tell me how to do.

Upvotes: 0

Views: 216

Answers (1)

camickr
camickr

Reputation: 324108

Try using a Card Layout which will allow you to swap panels.

The tutorial has a working example to get you started.

Upvotes: 1

Related Questions