Question

I've set an EmptyBorder around my JCheckBox (for the purpose of indenting it, but that doesn't really matter). When I select (or deselect) my JCheckBox, the border gets drawn around it as a dashed black line. I don't want to even see this border at all. How do I keep it invisible?

Here is my (simplified) code:

JPanel myPanel = new JPanel();
JCheckBox myCB = new JCheckBox("hello");
myPanel.add(myCB);
myCB.setBorder( new EmptyBorder( 2, 15, 2, 2 ) );
Was it helpful?

Solution

the border gets drawn around it as a dashed black line. I don't want to even see this border at all.

That is not a Border. That sounds like the focus indicator which indicates the component has focus. All components have some kind of focus indicator to give feedback to the user.

Companies spend millions of dollars to have a consistent LAF, but if you really think your LAF is better then you can use:

checkbox.setFocusPainted( false );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top