Reputation: 3229
I want to create Panel that stores multiple components, but only resizes the ones I want when I resize panel. For example if I have panel that stores 1 label and 2 textfields I want to be able to tell it to resize only textfields and not label size. Does any layout do that already or do I have to start learning to write custom layouts?
Upvotes: 0
Views: 150
Reputation: 30875
By default there is not layout manager that look at the type and then decide to act. You could use different containers to simulate that behavior, but implementing own layout manager would be more clean solution IMHO.
Upvotes: 0
Reputation: 36621
There are layout managers available which include that behavior (well, sort of). For example the FormLayout
from JGoodies allows to divide your panel in columns and specify the resize behavior of each of the individual columns.
A typical use case is where you have a form-like structure (column 1 containing a label, column 2 an input field) where you want on a resize to only resize the second column, ensuring visibility of the label and letting the input fields use all the extra space that is available.
Upvotes: 1
Reputation: 5967
You can explicitly set all sizes of components which you don't want to be resizable to same values.
For example:
Jlabel aLabel = new Jlabel("text");
Dimension d = new Dimension(50,20);
aLabel.setPreferredSize(d);
aLabel.setMinimumSize(d);
aLabel.setMaximumSize(d);
Upvotes: 0