Giannis Thanasiou
Giannis Thanasiou

Reputation: 299

Java add space between component and frame

I use a gridLayout(1,2) and I put a JLabel and JTextField on it. the result at the right end looks like this:

enter image description here

Is there a way to add more space between the border of the jframe and the jtextfield? So the jtextfield is not so close to the frame...

Upvotes: 0

Views: 2171

Answers (2)

Bart Hofma
Bart Hofma

Reputation: 644

Put an empty border around it:

    textField.setBorder(BorderFactory.createCompoundBorder(
    textField.getBorder(), 
    BorderFactory.createEmptyBorder(5, 5, 5, 5)));

Upvotes: 3

ControlAltDel
ControlAltDel

Reputation: 35096

Use Insets

JTextField jf = new JTextField() {
  public Insets getInsets() {
    return new Insets (5,5,5,50);
  }
}

Upvotes: 1

Related Questions