Relayout of JFrame?

K

Knute Johnson

I've got a JFrame app that has several components laid out with
GridBagLayout. One of the components is a JPanel that I draw an image
on. This component occaisionally can change size. After I resize my
JPanel, I invalidate it, repaint it and then call pack() on the JFrame.
Is there a way to cause the JFrame to relayout the components but not
shrink to fit the layout as it does with pack() but still grow if necessary?

Thanks,
 
B

Babu Kalakrishnan

Knute said:
I've got a JFrame app that has several components laid out with
GridBagLayout. One of the components is a JPanel that I draw an image
on. This component occaisionally can change size. After I resize my
JPanel, I invalidate it, repaint it and then call pack() on the JFrame.
Is there a way to cause the JFrame to relayout the components but not
shrink to fit the layout as it does with pack() but still grow if
necessary?

I'm afraid nothing that does it automatically. But you can always query
the panel for its preferredSize and set the size of the frame
appropriately - making it bigger if required, but not shrinking it if
that is the case.

BK
 
M

Martin Egholm Nielsen

I've got a JFrame app that has several components laid out with
GridBagLayout. One of the components is a JPanel that I draw an image
on. This component occaisionally can change size. After I resize my
JPanel, I invalidate it, repaint it and then call pack() on the JFrame.
Is there a way to cause the JFrame to relayout the components but not
shrink to fit the layout as it does with pack() but still grow if
necessary?
Try setting the minimumSize(Dimension d) to the minimum-size you want...
 
K

Knute Johnson

Babu said:
I'm afraid nothing that does it automatically. But you can always query
the panel for its preferredSize and set the size of the frame
appropriately - making it bigger if required, but not shrinking it if
that is the case.

BK

Thanks very much. That's kind of what I figured.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,133
Latest member
MDACVReview
Top