一个JRadioButton选择颜色 [英] JRadioButton selection color
问题描述
当选择在我的Java UI程序的任何单选按钮,选择通过的黑的圆点表示。我想让它绿色。我使用的Java Swing。我跟着给这个太问题的答案,但它不是为我工作。它仍然显示选中的时候有一个黑点。
公共类OptionFrame扩展的JFrame { 公共OptionFrame(){
UIManager.put(RadioButton.focus,新的将ColorUIResource(Color.GREEN));
SwingUtilities.updateComponentTreeUI(本);
}
}
我无法理解为什么上面code不工作。任何建议是高度AP preciated。
感谢。
我无法理解为什么上面code是行不通的。
块引用>由于这里讨论,外观是由外观和放大器控制;感觉依赖UI委托。委托是免费的呈现点但是它为所欲为;有些忽略默认和委托到主机平台组件。短写你自己的
ButtonUI
,替换图标
是退而求其次的。这例如说明了JToggleButton中
的选中状态的效果,一个JRadioButton父
。ColorIcon
,看到这里,也是方便在这一背景下,更多的例子被认为 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 theIcon
is the next best thing. This example illustrates the effect for the selected state ofJToggleButton
, the parent ofJRadioButton
.ColorIcon
, seen here, is also handy in this context, and more examples are seen here.这篇关于一个JRadioButton选择颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!