I'd like to create a GUI where some of the textfields are resizable horizontaly but maximum width is also specified. For instance the preferred width is 100 pixels, it can be bigger if the window is resized, but the maximum allowed width is 200 pixels. GroupLayout supports this, we can specify the max size in the addComponent method (alongside with minimum and preferred).

I'm using Netbeans and Swing GUI Builder (Matisse). I can set the textfield to be resizable, I can set the preferred size, but I've found no place to set the maximum size (and for the minimum). Here is the layout section of the property sheet:

Since maximum size cannot be set, Netbeans use Short.MAX_VALUE instead, so if a textfield is resizable it has no upper limit. I've also tried to set the maximumSize property of the component but it has no effect and will be ignored.

If I manually edit the .form file I can change the max="32767" part to max="200" and Netbeans generate correct code. Is there a way to set it without manually editing the .form file?

I've set the maximum size from the GUI before (5.5, 6.0, 6.1), but I don't have Netbeans on my work machine to verify it's still there. You might try changing the properties listing from groups to alphabetical.
–
James SchekDec 17 '09 at 15:47

Probably you're referring to the maximumSize property I've mentioned in the question. That's a different thing.
–
asalamon74Dec 17 '09 at 15:54

Did you ever resolve this issue? If so, what was the solution, and which version of the NetBeans was this?
–
John YearyDec 11 '12 at 18:23

2 Answers
2

I was looking at the options that are available on the JTextField component with regards to sizing of the component. These settings are suggestions (hints) to the LayoutManager. Ultimately, the LayoutManager determines the component size. In the case of Matisse and the .form object, the layout is controlled absolutely by the .form parameters. There is no automated method of manipulating the .form object from the standard API.

There is a tool called FormGenerator which was designed to try to generate .form objects from existing Swing objects. You may be able to use it to manipulate your .form file dyanmically.

Basically you override the layout that is build in the initComponents() method and set max size to wanted width instead of Short.MAX_VALUE. This worked for me. The window stopped re-sizing when at max size and also when at min size set in properties.