Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Preventing JTextFields from Resizing When Using SetText()

 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a GUI with several JTextFields that I populate with setText() with data read from a database. When the data read is longer than the size of the JTextField, the field resizes itself to accommodate the length of the data. However, this causes the whole GUI to become off-balance and look bad. I'd rather just have the data side-scrollable in the field without the size of the field changing. Does anyone know what I need to do? Thanks!
[ April 17, 2007: Message edited by: Scott Florez ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This really depends on the layout manager(s) you are using.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the setMinimumSize and setMaximumSize methods of the JTextField class. Using both with the same dimensions should fix the size of the field.
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The GUI is pretty complex, so I used NetBeans to design it. Therefore, I have no idea what length each text field needs to be. When I look at the code generated by Netbeans, the only dimensions specified are those of the gaps. Is there any other way to fix the sizes of the fields other than guessing over and over on each field's size (so I can can set the maximum and minimum sizes)? Thanks for the help.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Craig Wood:
You can try


I've been pretty behind with my other projects, so I just now got a chance to try this. Unfortunately, I'm still having the same problem. Any other suggestions?
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UPDATE:

I initially designed the GUI with NetBeans. I found that there is a constant value called Horizontal Resizable that you can toggle with a checkbox. Some of the text boxes were checked and some weren't. I unchecked all of the check boxes, but unfortunately I'm still having the same problem. It actually caused all of the text fields to lose alignment with each other, plus it didn't fix the initial problem. So I reverted back to the initial version. Does anyone have any other ideas on what I can do? Thanks!
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wanted to document the solution I found on the record. Using the setColumns() method fixed my problem. Thanks for all who looked at this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic