• Post Reply Bookmark Topic Watch Topic
  • New Topic

SWT Text - setSize ignored in GridLayout  RSS feed

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I am trying to set the width of a Text object to a fixed size (it's a zip code field so there aren't more than 5 characters going in) but for some reason the call to setSize is ignored.

Whats also odd is that when the text field is initialized and empty it has space to take 9 characters. When it is initialized with text it is only wide enough to take the characters. How come ??


Thanks
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Swing most layout managers ignore the size and use the preferred size instead. AWT's GridLayout uses the preferred size of the biggest components, to make sure all fit.

If this doesn't help you, you can still create a panel with a different layout (in AWT a FlowLayout comes to mind). Add the text field to that, then add the panel to the container. This notion of nesting layout managers is very common in Swing.

I hope this story applies to SWT as well.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!