Adeeb Mark
Adeeb Mark

Reputation: 67

Set a gap between the beginning of the JLabel and the icon

I have a Java Swing form and JLabel like this:

enter image description here

What I need to do is inserting a gap in the beginning of the JLabel:

enter image description here

So it will not stuck to the border line.

Note 1 : I already used jLabName.setIconTextGap(35); but it did the below:

enter image description here

I need to insert the gap before the icon not after it!

Note 2 : The Border Setting And Type And other setting:

enter image description here

Upvotes: 0

Views: 399

Answers (2)

Bugs - not a bug
Bugs - not a bug

Reputation: 73

You can use compound borders for that.

For Example.

//get border of your component which is button as you say
Border border = myButton.getBorder();

//create a new empty border with name it margin
Border margin = new EmptyBorder(0,10,0,0); //top 0, left 10 , bottom 0, right 0

//now set compound border to your button(component), with margin
myButton.setBorder(new CompoundBorder(border, margin));

//NOTE: CompoundBorder accepts two borders as arguments, first one is inner border and last one is outer border

Upvotes: 1

Adeeb Mark
Adeeb Mark

Reputation: 67

Fixed it with the following code:

a1.setBorder(new CompoundBorder(new EtchedBorder(), BorderFactory.createEmptyBorder(1, 8, 1, 1)));

Upvotes: 0

Related Questions