gpt4 book ai didi

java - JRadioButton选择颜色

转载 作者:行者123 更新时间:2023-11-30 04:32:02 24 4
gpt4 key购买 nike

当选择我的 Java UI 程序中的任何单选按钮时,所选内容将显示为一个点。我想把它变成绿色。我正在使用 Java Swing。我按照对此给出的答案SO Question ,但这对我不起作用。选择时它仍然显示一个黑点。

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.

正如所讨论的here ,外观由外观和感觉相关的 UI 委托(delegate)控制。代表可以随意呈现点;有些忽略默认值并委托(delegate)给主机平台组件。除了编写自己的 ButtonUI 之外,替换 Icon 是下一个最好的选择。这个example说明了 JToggleButton(JRadioButton 的父级)的选定状态的效果。 ColorIcon,参见 here ,在这种情况下也很方便,可以看到更多示例 here .

关于java - JRadioButton选择颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com