• 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Why JTextField takes all available space in Box?  RSS feed

 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have my JTextField,a few JButtons inside javax.swing.Box.

Later in code I add JButtons into Box toolbarBox:

As you saw toolbarBox contains JTextField and horizontalGlue and later added JButtons.
The problem is that all available free space is occupied by JTextField but I want it to have fixed width and Box.createHorizontalGlue() should take all rest space. All JButtons have fixed width but JTextField stretches to take up all rest space in my horizontal Box?
How to make JTextField to be of fixed size and Box.createHorizontalGlue() take all rest space?

Thank you!
 
Rancher
Posts: 2974
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your SSCCE that demonstrates the problem?
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I posted already all relevant code!
ObjectsListPanel contains field private JTextField searchField;
This searchField is added into private Box toolbarBox as the rightmost element at line 13. Next horizontal glue is added at line 14. Next JButtons are added which is hapenning later dynamically.
Box toolbarBox is long and JButtons do not accupy all available space of toolbarBox. The problem is that searchField stretches itself to take up all available width but I want searchField to be of fixed width. Now width of searchField depends on width of toolbarBox and amount of JButtons in it.
How to make JTextField to be of fixed width in Box toolbarBox?
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check http://sscce.org/ to understand what SSCCE really means
 
Rob Camick
Rancher
Posts: 2974
20
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I posted already all relevant code!



When you have a problem you don't know what code is or isn't relevant until the problem is solved.

That is why you post a SSCCE which is the minimal amount of code that demonstrates the problem when we execute the code.

If you would have posted a SSCCE with your question you probably would have had your answer by know. Who know the next time I will be at the forum so you likely need to wait hours again after you finally post your code.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!