2

I have a Swing application created in Netbeans using Matisse GUI builder. One of the panels I created looks like this:

enter image description here

I want to use this panel in two scenarios:

  • use it to enter data. Then the form is used as it would be obvious. When resizing, the text fields grow horizontally to fill the available space.
  • use it to just display data. In that case the textfields are setEnabled(false) and the buttons are setVisible(false).

All this works quite well, but I am wondering about the textfield sizes when the buttons are disabled, as they do not all grow the same. Here you can see the panel in the two scenarios:

enter image description here

enter image description here

While I am pretty sure the correct settings can be done in the GUI builder I am not sure what I need to look at. Where do you edit such constraints as of where a component is anchored (left, right, top, down and whether it is the next sibling or the parent) and how it should move/grow upon resize? I just do not see the relevant buttons or menus in Netbeans/Matisse. Could it be that I just need to look at the correct use of Glue and fillers?

I am aware I could switch to other layout managers but like the optical effect of having a common baseline on the text.

Queeg
  • 7,748
  • 1
  • 16
  • 42

2 Answers2

1

Meanwhile I found some documentation in the Netbeans Tutorials.

The secret is to tell Matisse how to align the components, and it cannot be done just by dragging and dropping or resizing them. So what I did was to select all the text fields (click them one by one while holding Ctrl), then press the now available "Align left in column" button. Finally I did the same with the buttons.

enter image description here

The result is what I expected to have. :-)

enter image description here

enter image description here

Queeg
  • 7,748
  • 1
  • 16
  • 42
0

If you want total control of the components layout you will need to use the Null Layout. It's not recommended, since the layout managers are responsible for making yout GUI "responsive" when maximized, etc. When using Group Layout, the default layout manager used by Matisse, you will have these "strange" behaviors when setting invisible components. One way to prevent if to group your components in containers like JPanels. In your scenario, you could use a JPanel to group all your buttons. You can also change the horizontal and vertical resizability of the components. Take a look in the image. These options are highlighted in orange. The first two examples are with the horizontal resizability turned on. The third example is with this property turned off.

enter image description here

In yout scenario, I would use a Grid Bag Layout and JPanels to organize my components. To change the layout manager, right click inside yout JFrame -> Set Layout -> Grid Bag Layout:

enter image description here

To customize it, right click -> Customize Layout:

enter image description here

enter image description here

davidbuzatto
  • 9,207
  • 1
  • 43
  • 50
  • I'd like to stay on GroupLayout. If I place the textfields and the buttons into different JPanels I think I will loose the effect of a common text baseline across the label, the text field and the button. The question is also not how to make one textfield grow. The question is how to ensure they all grow the same way. – Queeg Jul 15 '23 at 20:29