将 ButtonGroup 添加到 Box-layout 对象
当我尝试将 ButtonGroup
对象放入我的 Box
对象时,编译器返回以下错误:
没有这种类型的方法
请帮助我,如何将我的 ButtonGroup
添加到 Horizontal Box 中?
When I try to put ButtonGroup
object to my Box
object, compiler returns the following error:
no method for such a type
Please help me, how can I add my ButtonGroup
into Horizontal Box?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的事情:
Something like this:
ButtonGroup 扩展了 Object;它不是一个组件。因此它没有显式添加到容器或组件中。相反,它对 AbstractButton 实例进行分组。
以下是 Java 文档中的示例代码。
不将 ButtonGroup 设为组件的一个优点(可能也是以这种方式实现它的原因)是,您可以让不同组件上的 AbstractButton 实例成为同一 ButtonGroup 的成员。
下面是一些使用 BoxLayout 来演示它的示例代码。
The ButtonGroup extends Object; it is not a Component. So it is not explicitly added to a Container or Component. Rather, it groups AbstractButton instances.
Here is the example code from the Java documentation.
One advantage of not making ButtonGroup a Component (and probably the reason for implementing it this way) is that you can have AbstractButton instances on different Components be member of the same ButtonGroup.
Here is some sample code to demonstrate it, using a BoxLayout.