How to set JLabel border?

I have a JLabel for which I want to add margin. It looks like this:

enter image description here

I read about setting an empty border with a certain thickness, but that would replace the current border. How to add this stock?

+6
source share
1 answer

"I read about setting up an empty border with a certain thickness, but that will replace the current border. How can I add this margin?"

See CompoundBorder

The component Border class used to create two Border objects into a single border by nesting inside the Border object inside the attachments of the external Border object. For example, this class can be used to add a space to a field with a component with an existing decorative border:

 Border border = comp.getBorder(); Border margin = new EmptyBorder(10,10,10,10); comp.setBorder(new CompoundBorder(border, margin)); 

Also see EmptyBorder

+15
source

All Articles