Search code examples
javaswingjtextfield

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.


Solution

  • 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