Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

SWT Text - setSize ignored in GridLayout  RSS feed

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 ??

Posts: 21453
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!