I want to leave the default border on my JButtons, but also place blank space around them. I use vertical BoxLayout.
I initially did not say anything about borders and got one pixel LineBorders that I want, but all the buttons were connected to each other.
Then I tried button[i].setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)). Instead of adding empty space around the button, it increased the area of โโthe buttons. He also deleted LineBorder.
Then I tried: button[i].setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(5, 5, 5, 5), button.getBorder()))
This returned me LineBorder, but instead of adding white space outside the line, it just expanded the button areas outside the line!
I understand that I can add empty boxes to touch my buttons, but I also need space on the sides, so I want to add EmptyBorder. I'm new to Swing, so maybe there is a better way to do this that I don't know about :)
I am using Jython, but the API should be the same as Java.
source
share