Link to home
Create AccountLog in
Avatar of Cmerf486

asked on

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
Avatar of CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Cmerf486


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.
Avatar of Bart Cremers
Bart Cremers
Flag of Belgium image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Cool. Thanks Bart_Cr. That helped, I guess I also needed to give the components a weightx and weighty value on the gridbagconstraints.