Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField size changes with JLabel text length  RSS feed

 
Sam Pereira
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create 3 JTextFields in a row with all being of equal size.But my first Text field gets so wide than the other two.After adding each component at a time and seeing what causes the problem I realized that if I type a long text for the JLabel that's when this problem occurs.If I reduce the length of the text in the JLabel JTextFields get into the sizes I want.Here's my code




How can I stop the JTextFields changing size when I change the JLabel label1's text length
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the fill constraints to go with those Components?
Have you come across Cai Horstmann's GBC class which makes Grid Bag easier to use?
 
Sam Pereira
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using gridBagConstraints.HORIZONTAL
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Won't that cause the text fields to change size to match the text? I can't remember.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Pereira wrote:I want to create 3 JTextFields in a row with all being of equal size.


Then put them into a FlowLayout. If you don't want a JLabel to affect their size, then don't put that JLabel into that layout. Put it into another layout.
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or a grid layout or a box layout.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!