Well this is pretty simple, I'm wondering how I ensure that my JFrame or JInternalFrame has a certain minimum size. I'm using GridBagLayout and at a certain point the components inside it, labels, text fields, etc. stop scaling and instead start moving becoming a jumbled overlapping mess of components. Basically, rather than trying to make it so that these components have no minimum size I'd rather just make it impossible for the frame to become small enough for that to happen, but I'm not sure how do this and I haven't found anything that shows me after searching. I know that I can use a ComponentListener and when it gets too small directly change the size to be big enough but that doesn't seem to work while dragging and I'm sure that can't be the best way. So, what's the proper way of handling this as I tried setting a minimum size for the frame and that didn't seem to work. The other thing I want to know is how I go about finding out what this minimum size should be since it could vary depending on the look & feel, font, etc. Any help or direction is appreciated.
You could put a panel inside a scrollpane and then set minimum, preferred and maximum sizes on the panel so that it is always well laid out. Users will just see less of the panel if they decrease the frame size, but can still scroll the complete panel.
The nice thing about Standards is that there are so many to choose from!
posted 16 years ago
That doesn't really address the problem. Besides if I use a scroll pane the components will use their preferred sizes instead of resizing forcing the user to scroll around when they shouldn't have to.
I ran across this situation and after searching came up with the following. It ain't exactly pretty, but it does work.
Obviously you could get the min values (MIN_WIDTH and MIN_HEIGHT) some other way. You listen for resize events on the frame and if the user tries to go below some minimum threshhold, you increase to the mininum height or width or both. It's easy and it works.
posted 16 years ago
As I mentioned I knew I could use a component listener but that doesn't seem to work during drag and I figured there MUST be a better way. There isn't some minimum size that I can set somewhere or something?
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!