gpt4 book ai didi

java - 丰富的 Swing 单选按钮

转载 作者:行者123 更新时间:2023-11-29 08:17:47 24 4
gpt4 key购买 nike

开发基于 Java + Swing 的桌面应用程序 我遇到了创建一个单选按钮的问题,该按钮旁边应该有图像,而不是旁边的文本,或者说,另一个像微调器这样的小部件。

点击图片或微调器也应该选择相应的单选按钮。

这可能吗?如果是,怎么办?

最佳答案

对我来说,为构造函数提供图标的 JRadioButton 似乎不起作用;它用给定的图标替换了“ native 单选按钮图标”。我认为除了“单选按钮图标”之外,还需要带有图标的单选按钮。

关于 Bug #4177248 的 Sun 错误数据库的行为存在一些争论。但未进行任何更改。

相反,可以尝试 JRadioButtonMenuItem ,即使可能会有一些不需要的行为?

对 JRadioButton 和 JRadioButtonMenuItem 的简短评估:

public class IconRadioButtonEval {
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
// Use some arbitrary working URL to an icon
URL url =
new URL(
"http://mikeo.co.uk/demo/sqlspatial/Images/RSS_Icon.png");
Icon icon = new ImageIcon(url);
JRadioButton button = new JRadioButton(icon);
panel.add(new JLabel("RadioButton with icon:"));
panel.add(button);
panel.add(new JLabel("RadioButtonMenuItem with icon:"));
panel.add(new JRadioButtonMenuItem(icon));

frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}

Justin 建议在 JRadioButton 旁边使用空字符串的另一个组件在大多数情况下应该可以正常工作。

关于java - 丰富的 Swing 单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3149711/

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