选中复选框后,JCheckBox 周围的 EmptyBorder 变得可见 [英] EmptyBorder around JCheckBox becomes visible when checkbox selected
问题描述
我在我的 JCheckBox
周围设置了一个 EmptyBorder
(为了缩进它,但这并不重要).当我选择(或取消选择)我的 JCheckBox
时,边框会以黑色虚线的形式围绕它绘制.我什至不想看到这个边界.如何让它不可见?
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 ) );
推荐答案
边框以黑色虚线绘制在其周围.我什至不想看到这个边界.
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.
公司花费数百万美元来获得一致的 LAF,但如果您真的认为自己的 LAF 更好,那么您可以使用:
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 );
这篇关于选中复选框后,JCheckBox 周围的 EmptyBorder 变得可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!