I want to leave the default border on my JButton
s, but put empty space around them as well. I'm using a vertical BoxLayout
.
I originally said nothing about the borders, and got single pixel
LineBorder
s, which I want, but the buttons all butted up against each other.I then tried
button[i].setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5))
. Rather than adding blank space around the button, it made the buttons' areas expand. It also removed theLineBorder
.I then tried:
button[i].setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(5, 5, 5, 5), button.getBorder()))
This gave me back the LineBorder
, but rather than adding blank space outside the line, it just extended the buttons' areas beyond the line!
I realise I can add blank boxes to space my buttons out, but I want space on the sides of them as well, which is why I want to add an EmptyBorder
. I'm new to Swing, so maybe there's an entirely better way of doing this that I don't know about :)
I'm using Jython, but the API should be the same as from Java.