I have a JLabel (actually, it is a JXLabel).
I have put an icon and text on it.
<icon><text>
Now I wand to add some spacing on the left side of the component, like this:
<space><icon><text>
I DON'T accept suggestion to move the JLabel or add spacing by modifying the image.
I just want to know how to do it with plain java code.
I have found the solution!
setBorder(new EmptyBorder(0,10,0,0));
Thanks everyone!
The like this: is not very clear, but you can add spacing by adding a transparent border of a certain width to the label
If you're trying to push the label to one side of it's container, you can add a glue. Something like this:
JPanel panel = new JPanel();
panel.setLayoutManager(new BoxLayout(panel, BoxLayout.LINE_AXIS);
panel.add(new JLabel("this is your label with it's image and text"));
panel.add(Box.createHorizontalGlue());
Though your question isn't very clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With