Swing: remove focus border from dialogues' buttons

家住魔仙堡 提交于 2019-11-28 01:30:27
  • from JButtons API you can to use JButton.setFocusable() and with JButton.setBorderPainted(false);

  • from UIManager have to override key (valid for whole JVM instance)

.

UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("Button.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
  • I'd to suggest to change Color with transparency (4th paramater in a.m. code) to another more decent Color, otherwise you can't to see focus for any of `JButtons

What about

JButton.setFocusPainted(false)
Goombert

Here's a global fix so you don't have to do it manually for every control. From my other post: Disable JButton focus border

        // Removes the dotted border around controls which is not consistent with Windows
        UIManager.put("Button.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
        UIManager.put("ToggleButton.focus", new ColorUIResource(new Color(0, 0, 0, 0)));

        // ways to remove it from other controls...
        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)));

        // figure out combobox
        UIManager.put("ComboBox.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!