Question

I would like to dynamicly replace/change to contents of a panel. I know that the "standard" way of doing this is to use the CardLayout.

However, most of the Components are very fat. They are big data tables and huge diagrams.

What other options do I have (including 3rd party components available for free)?

Was it helpful?

Solution

You can delete old content and create new and readd the new component(s). Then call

container.revalidate(); 
container.repaint();

OTHER TIPS

Just don't use a LayoutManager. Bake it yourself:

// start with fat compponent 1
JPanel p = new JPanel(new BorderLayout());
FatComponent1 c1 = new FatComponent1();
p.add(c1, BorderLayout.CENTER);

// ...
// replace it e.g. after pressing a button with fat component 2
p.removeAll();
FatComponent2 c2 = new FatComponent2();
p.add(c2, BorderLayout.CENTER);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top