JRadioButton selection color

假装没事ソ 提交于 2019-12-11 11:01:27

问题


When any Radio Button in my Java UI program is selected, the selection is shown by a black dot. I want to make it Green. I'm using Java Swing. I followed the answer given to this SO Question , but it's not working for me. It still shows a black dot when selected.

public class OptionFrame extends JFrame {

     public OptionFrame(){
            UIManager.put("RadioButton.focus", new ColorUIResource(Color.GREEN));
            SwingUtilities.updateComponentTreeUI(this);
     }
}

I'm unable to understand why above code is not working. Any suggestions are highly appreciated.

Thanks.


回答1:


I'm unable to understand why above code is not working.

As discussed here, the appearance is controlled by the Look & Feel dependent UI delegate. The delegate is free to render the dot however it pleases; some ignore the defaults and delegate to a host platform component. Short of writing your own ButtonUI, replacing the Icon is the next best thing. This example illustrates the effect for the selected state of JToggleButton, the parent of JRadioButton. ColorIcon, seen here, is also handy in this context, and more examples are seen here.



来源:https://stackoverflow.com/questions/14406329/jradiobutton-selection-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!