Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextField suddenly too small

Screenshot:

image

The textfield always worked fine, but suddenly was too small. You can still enter text, and when clicking the Print textJOptionPane.

I also tried both

JTextField tfld = new JTextField(10);

and

JTextField tfld = new JTextField("test adlfjsdlfjasdf");

but neither one helped.

like image 318
bertcc423 Avatar asked Dec 03 '25 10:12

bertcc423


2 Answers

Sounds like you are using a GridBagLayout. This happens on components that don't have a reasonable minimum size.

like image 156
camickr Avatar answered Dec 04 '25 23:12

camickr


try you use

         txtfield.setPreferredSize(new Dimension(int,int));

it will take parameters for Dimension you can read this for further assistance

http://docs.oracle.com/javase/6/docs/api/javax/swing/JComponent.html#setPreferredSize%28java.awt.Dimension%29

like image 39
Tech Nerd Avatar answered Dec 04 '25 23:12

Tech Nerd