Disable JButton focus border

前端 未结 5 1067
说谎
说谎 2020-12-15 16:38

I have a problem with JButton in Java. Basically, I want to disable the button\'s border (the button is added to JDesktopPane ).

Here is my code :

          


        
5条回答
  •  被撕碎了的回忆
    2020-12-15 17:19

    After digging I have come up with a better solution. This is also a common UI bug in GTK applications on Windows, one of them being GIMP. It greatly annoys me so I wanted to find a better fix global fix than setting it on every control manually.

    The workaround sets the color for the focus on all the common controls that it's not supposed to occur to transparent. I went and tested extensively with Windows Forms in Visual Studio. Toolbar buttons and ToggleButtons should never have the dotted border even when focused. Toolbars are supposed to be setFocusable(false); by default as they are in Windows. Every other control should have the dotted border as in Swing, but only when being focus cycled.

            // 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)));
    

提交回复
热议问题