将 JRadioButton 添加到 RadioButton 组

发布于 2024-12-25 17:20:33 字数 386 浏览 3 评论 0原文

美好的一天

想知道如何通过将组件拖放到框架上来将单选按钮添加到 ButtonGroup 中。

JRadioButton male = new JRadioButton("Male");
JRadioButton female = new JRadioButton("Female");
ButtonGroup bg = new ButtonGroup();
bg.add(male);
bg.add(female);
pane.add(male);
pane.add(female);

我怎样才能通过简单的拖放来做到这一点。如果我将 ButtonGroup 放到框架上,它将被分组在“其他组件”下,从那里我不确定如何将单选按钮添加到按钮组。

谢谢 问候阿里安

Good day

Would like to know how to add radiobuttons to a ButtonGroup by dragging and dropping components on to the frame.

JRadioButton male = new JRadioButton("Male");
JRadioButton female = new JRadioButton("Female");
ButtonGroup bg = new ButtonGroup();
bg.add(male);
bg.add(female);
pane.add(male);
pane.add(female);

How can I do this by simple dragging and dropping. If I drop the ButtonGroup onto the frame it gets grouped under 'other components' and from there I am not exactly sure how to add radio buttons to the button group.

thanks
regards Arian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆沫 2025-01-01 17:20:33

您已经查看了 HierarchyListenerhierarchyChanged 事件,您已将新的 JRadioButton 添加到 ButtonGroup 中,仔细了解最后知道的具体 isSelected JRadioButton

you have look at HierarchyListener, on hierarchyChanged event you have add a new JRadioButton to the ButtonGroup, carefully with last know isSelected for concrete JRadioButton

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文