EmptyBorder around JCheckBox becomes visible when checkbox selected

回眸只為那壹抹淺笑 提交于 2020-01-07 02:32:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!