Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

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
0
Cmerf486
Asked:
Cmerf486
  • 2
1 Solution
 
CEHJCommented:
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
0
 
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.
0
 
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
0
 
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now