简体   繁体   English

JRadioButton,看起来像JButton

[英]JRadioButton that looks like JButton

I'm trying to create a feature similar to that of Geogebra 's toolbar: it has buttons that select tools, so only one can be selected at a time, but they don't look like radio buttons (a dot, with an inner dot if it's selected); 我正在尝试创建一个类似于Geogebra工具栏的功能:它具有选择工具的按钮,因此一次只能选择一个,但它们看起来不像单选按钮(一个点,带内部点如果被选中); they look like JButton s with an ImageIcon . 它们看起来像带有ImageIcon JButton

I've gone through some of the source (specifically ModeToggleMenu.java and Toolbar.java ) but still can't quite figure out what's happening. 我已经浏览了一些源代码(特别是ModeToggleMenu.javaToolbar.java ),但仍然无法弄清楚发生了什么。 I just need something basic. 我只需要一些基本的东西。 I would really appreaciate help! 我真的会帮助你!

Screenshot of what I mean: 我的意思是屏幕截图:

Geogebra工具栏的图像

Note the pointer, point, line, perpendicular line, triangle, etc.. That's the effect I'm trying to achieve. 注意指针,点,线,垂直线,三角形等。这就是我想要达到的效果。

Thanks very much! 非常感谢!

I think the little thing that you missed is that the Geogebra code you linked to uses this as the button class: 我认为您遗漏的小事是您链接的Geogebra代码使用它作为按钮类:

class MyJToggleButton extends JToggleButton

So the buttons are JToggleButtons not JRadioButtons. 所以按钮是JToggleButtons而不是JRadioButtons。 JToggleButtons can be used directly and put into button groups just like radio buttons. JToggleButtons可以直接使用,并像单选按钮一样放入按钮组。 Geogebra's code does custom painting, but you can just set an icon as well. Geogebra的代码可以自定义绘制,但您也可以设置一个图标。

Create custom icons then use: 创建自定义图标然后使用:

radioButton.setIcon(...);
radioBbutton.setSelectedIcon(...);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM