• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why JTextField takes all available space in Box?

 
Volodymyr Lysenko
Ranch Hand
Posts: 512
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!
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your SSCCE that demonstrates the problem?
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
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?
 
Maneesh Godbole
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
Ranch Hand
Posts: 2699
10
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!