一个JRadioButton选择颜色 [英] JRadioButton selection color

查看:174
本文介绍了一个JRadioButton选择颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当选择在我的Java UI程序的任何单选按钮,选择通过的的圆点表示。我想让它绿色。我使用的Java Swing。我跟着给这个太问题的答案,但它不是为我工作。它仍然显示选中的时候有一个黑点。

 公共类OptionFrame扩展的JFrame {     公共OptionFrame(){
            UIManager.put(RadioButton.focus,新的将ColorUIResource(Color.GREEN));
            SwingUtilities.updateComponentTreeUI(本);
     }
}

我无法理解为什么上面code不工作。任何建议是高度AP preciated。

感谢。


解决方案

  

我无法理解为什么上面code是行不通的。


由于这里讨论,外观是由外观和放大器控制;感觉依赖UI委托。委托是免费的呈现点但是它为所欲为;有些忽略默认和委托到主机平台组件。短写你自己的 ButtonUI ,替换图标是退而求其次的。这例如说明了 JToggleButton中的选中状态的效果, 一个JRadioButton父 Col​​orIcon ,看到这里,也是方便在这一背景下,更多的例子被认为 href=\"http://stackoverflow.com/q/6774987/230513\">。

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.

解决方案

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.

这篇关于一个JRadioButton选择颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆