5

I wonder how can I remove this grey border from buttons in dialogues? enter image description here

For simple JButtons I found a solution - just use button.setFocusPainted(false); But is there a simple way to perform the same for all buttons in all dialogues? I tried to look through UIManager properties, but it seems that there are no suitable parameters there. enter image description here

Thanks in advance!

Kirill Smirnov
  • 1,452
  • 2
  • 21
  • 28
  • *"..how can I remove this dashed grey border from buttons in dialogues?"* Why are you intent on making yet another unusable GUI? Those dashes are there to show focus. Leave them be. – Andrew Thompson Nov 17 '12 at 02:51
  • 1
    @Andrew Thompson Well, you're right - removing focus border affects usability, but I can offer two arguments. 1) I use message dialogues with only one button in my application (first picture in my post was taken from Oracle's website), so I suppose focus border is useless in such case. 2) I find this border really inappropriate, may be it would be better to draw it only around whole button, not around button's text. – Kirill Smirnov Nov 17 '12 at 08:41

3 Answers3

9
  • 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
mKorbel
  • 109,525
  • 20
  • 134
  • 319
6

What about

JButton.setFocusPainted(false)
Charles V.G.
  • 169
  • 4
  • 11
1

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)));
Community
  • 1
  • 1
Goombert
  • 314
  • 3
  • 13