问题
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 ) );
回答1:
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 );
来源:https://stackoverflow.com/questions/22970712/emptyborder-around-jcheckbox-becomes-visible-when-checkbox-selected