经过一番探究,我找到了更好的解决方案。在 Windows 上的 GTK 应用程序中,这也是常见的 UI bug 之一,其中之一就是 GIMP。这极大地困扰着我,所以我想找到一个更好的全局修复方法,而不是手动设置每个控件。
解决方法是将所有常见控件上的焦点颜色设置为透明。我在 Visual Studio 中使用 Windows Forms 进行了广泛的测试。即使聚焦,工具栏按钮和 ToggleButtons 也不应该有虚线边框。工具栏默认情况下应该被设置为 setFocusable(false) ,因为它们在 Windows 中是这样的。其他所有控件都应像 Swing 一样具有虚线边框,但仅在进行焦点循环时才需要。
UIManager.put("Button.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
UIManager.put("ToggleButton.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
UIManager.put("CheckBox.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
UIManager.put("TabbedPane.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
UIManager.put("RadioButton.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
UIManager.put("Slider.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
UIManager.put("ComboBox.focus", new ColorUIResource(new Color(0, 0, 0, 0)));