JRadioButton 看起来像 JButton
我正在尝试创建一个类似于 Geogebra 工具栏的功能:它有选择工具的按钮,因此一次只能选择一个,但它们看起来不像单选按钮(一个点,如果选择了则带有一个内部点);它们看起来像带有 ImageIcon
的 JButton
。
我已经浏览了一些源代码(特别是 ModeToggleMenu.java 和 Toolbar.java)但仍然可以'不太明白发生了什么。我只需要一些基本的东西。我真的很感激帮助!
我的意思的屏幕截图:
注意指针、点、线、垂直线、三角形等。这就是我想要达到的效果。
非常感谢!
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); they look like JButton
s with an ImageIcon
.
I've gone through some of the source (specifically ModeToggleMenu.java and Toolbar.java) but still can't quite figure out what's happening. I just need something basic. I would really appreaciate help!
Screenshot of what I mean:
Note the pointer, point, line, perpendicular line, triangle, etc.. That's the effect I'm trying to achieve.
Thanks very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建自定义图标然后使用:
Create custom icons then use:
我认为您错过的一件小事是您链接到的 Geogebra 代码使用它作为按钮类:
所以按钮是 JToggleButtons 而不是 JRadioButtons。 JToggleButtons 可以直接使用,并像单选按钮一样放入按钮组中。 Geogebra 的代码可以进行自定义绘画,但您也可以只设置一个图标。
I think the little thing that you missed is that the Geogebra code you linked to uses this as the button class:
So the buttons are JToggleButtons not JRadioButtons. JToggleButtons can be used directly and put into button groups just like radio buttons. Geogebra's code does custom painting, but you can just set an icon as well.