chillysapien chillysapien - 1 year ago 89
Java Question

Resize a JPanel in line with a JDialog

I've got a

which contains a series of
in a
. Some of these panels contain
which I would like to be resized in line with any resizing of the
. I am not sure how to achieve this and any help would be greatly appreciated.

At present the tables simply remain their current size and do not scale. I'm sure its something simple but I'm having trouble locating the exact approach needed.

Many thanks in advance. I will provide any more information if required.

edit: The
is used as a wizard, so only one of the panels is being displayed at any one time, hence the use of
. I would ideally like to keep this is layout manager, although if it is the source of the problems then obviously I would rethink!

Answer Source

You can keep the CardLayout, but you need to do the following: 1. set the layout of your JDialog to BorderLayout, and add a new JPanel (contentPanel) to the JDialog
2. now set this contentPanel layout to be CardLayout
3. add your other panels to the cardlayout as required.
4. Also make sure off the layouts you use on each of the panels you're adding to the CardLayout. By default JPanel uses FlowLayout, I think, and this is not ideal for a JTable. So you might need to play around with the layout of the panel containing the table as well; try out BoxLayout or BorderLayout for that as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download