0

There are TextFields , four , contained into a Container whose Layout is BoxLayout(BoxLayout.Y_AXIS). I want each of these TextFields to have their own width. I tried setPreferredW , also setColumns but the TextFields are all the same size which is occupying all the remaining row's width.

So how to make each or some TextFields have their own width visually ?

2 Answers2

1

BoxLayout always stretches components on the opposite AXIS so the text fields will always stretch regardless of their preferredW (another reason why you must never mess with that value unless you know what you are doing...).

The solution is simple, nest the text fields in multiple FlowLayout/BoxLayoutX containers and add the containers one by one to the box layout Y. The containers will each occupy the full width of the Y AXIS container but the text fields within won't take up all the space.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Container lines = new Container(new BoxLayout(BoxLayout.Y_AXIS); Container l = new Container(); l.addComponent(label); l.addComponent(tf); lines.addComponent(l); – Shai Almog Sep 25 '11 at 04:01
1

I found the solution : I derived the TextField class and in the constructor I set the preferred width value.

PS : I did not call super();