Hannah
Hannah

Reputation: 57

Java Swing TextField looking very small

I am trying to add a textfield next to some check boxes, but for some reason it looks only 1 char in size?

JButton addStaff = new JButton("Add Staff");
westPanel.add(addStaff);
// bind the button with the listener
addStaff.addActionListener(new StaffHandler());
c1 = new JCheckBox("Home Only?");
westPanel.add(c1);
c2 = new JCheckBox("Offer ShortHand?");
westPanel.add(c2);
t1 = new JTextField("");
westPanel.add(t1);

My output is the following, which looks a bit rubbish. Screenshot of the resulting Swing

Upvotes: 1

Views: 1195

Answers (1)

Pradnyarani
Pradnyarani

Reputation: 302

You can use the constructor new JTextField(int columns)

e.g. JTextField t1 = new JTextField(20);

Upvotes: 3

Related Questions