Problem with JPanel in Java Swing

0

Hello, how are you? I'm new to the community. I come to consult you about a problem that I have with Java Swing. The issue is, in short, that I have a JFrame to which I set an empty JPanel, something like this:

principal = new JPanel (); getFrm (). getContentPane (). add (main);

and then later, I would like to be able to change the content of "main", for what I do ...

principal = new JPanel (); // (1)

principal.add (new JButton ("example");

But I can not see any change (even if I call repaint or revalidate). Where I do see changes is if in (1) I replace the line with "principal.removeAll ()"

Am I doing things right? To make clear I would like to "empty" all the contents of a panel to be able to reuse it at runtime, and my common sense leads me to make a "new" panel, but it does not work.

    
asked by Hernan Z 24.09.2017 в 08:20
source

0 answers