3

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
bertcc423
  • 203
  • 1
  • 4
  • 6
  • 3
    This is probably due to your layout manager. Can you post a Short, [Self Contained, Correct (Compilable), Example](http://sscce.org/)? – Reimeus Apr 27 '13 at 12:32
  • A related example is examined [here](http://stackoverflow.com/a/12532237/230513). – trashgod Apr 27 '13 at 12:47

2 Answers2

4

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

camickr
  • 321,443
  • 19
  • 166
  • 288
3

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

Afshin Moazami
  • 2,092
  • 5
  • 33
  • 55
Tech Nerd
  • 822
  • 1
  • 13
  • 39