2

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)?

marc m
  • 23
  • 2

2 Answers2

2

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

container.revalidate(); 
container.repaint();
StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • @marc m plus put `big data tables and huge diagrams` to the `JScrollPane` +1 – mKorbel Aug 26 '11 at 07:00
  • There's a related example [here](http://stackoverflow.com/questions/7059278/change-panel-size-on-button-click/7061696#7061696). – trashgod Aug 26 '11 at 07:04
1

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);
Marcel
  • 3,749
  • 6
  • 29
  • 35
  • Because the used components are very fat (high memory consumption, need long initialization time etc.) – Marcel Sep 21 '11 at 11:44