How do I dynamically resize components according to framesize in a GUI?

I am trying to develop an application that has to create JTables from database queries on the fly. Creating the table is not a problem, but it has been requested that the form be resizable. I have the table set into a JScrollPane. How do I
1). resize the table without resizing the scrollpane?
2). resize the scrollpane to fit the resized frame?

This table shares the form with a lot of other components and I am looking at using either a null layout or a gridbag layout
Who is Participating?
Bart CremersJava ArchitectCommented:
Using the GridBagConstraints you can tell the layout manager which components should take up the extra space.

Use GridBagConstraints.fill to achieve this. Fill can be set to GridBagConstraints.NONE (default), GridBagConstraints.HORIZONTAL, GridBagConstraints.VERTICAL, GridBagConstraints.BOTH
The best thing to do is to use a layout manager or you'll have to do all resizing calculations yourself. Using a layout manager means it should all happen automatically
Cmerf486Author Commented:
I don't think I asked the right question. How do I resize the components in my frame whenever a user resizes the frame itself? Using the gridbag layout, the components stayed centered, but did not resize.
Cmerf486Author Commented:
Cool. Thanks Bart_Cr. That helped, I guess I also needed to give the components a weightx and weighty value on the gridbagconstraints.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.