File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Preventing JTextFields from Resizing When Using SetText() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Preventing JTextFields from Resizing When Using SetText()" Watch "Preventing JTextFields from Resizing When Using SetText()" New topic
Author

Preventing JTextFields from Resizing When Using SetText()

Scott Florez
Ranch Hand

Joined: Dec 05, 2006
Posts: 58
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

Joined: Jan 14, 2004
Posts: 1535
This really depends on the layout manager(s) you are using.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42046
    
  64
Check out the setMinimumSize and setMaximumSize methods of the JTextField class. Using both with the same dimensions should fix the size of the field.


Ping & DNS - my free Android networking tools app
Scott Florez
Ranch Hand

Joined: Dec 05, 2006
Posts: 58
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

Joined: Jan 14, 2004
Posts: 1535
You can try
Scott Florez
Ranch Hand

Joined: Dec 05, 2006
Posts: 58
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

Joined: Dec 05, 2006
Posts: 58
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

Joined: Dec 05, 2006
Posts: 58
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.
 
GeeCON Prague 2014
 
subject: Preventing JTextFields from Resizing When Using SetText()