更改Jcombobox元素的数据类型

发布于 2025-01-22 00:19:56 字数 1045 浏览 2 评论 0原文

我需要制作一个装有jradiobuttons作为条目的Jcombobox。因此,它看起来像一个下拉盒,其中有几个可以选择的jradiobuttons。因此,我使用了以下代码:

JComboBox<JRadioButton> deg=new JComboBox();
DefaultComboBoxModel<JRadioButton> degModel=new DefaultComboBoxModel<>();
degModel.addElement(new JRadioButton("This Button));
deg.setModel(degModel);

因此,自然而然地,我希望下拉菜单的jradiobuttons菜单,但是我碰巧看到了类似的东西:

“在此处输入映像说明”

因此,似乎出于某种原因,出于某种原因,该条目类型尽管我试图将类型设置为Jradiobuttons,但Jcombobox并没有改变,但它仍在尝试制作字符串数据类型的Jcombobox,因此显示了提到的Jradiobutton的ToString。

我还发现此链接与问题有关,但这只是Netbeans上的一个选项(据我所知),这很奇怪,更改内置编译器选项与某个类别的功能如何相关。

谁能帮我解决这个问题?任何帮助将不胜感激!
(我还需要jradiobutton在单击时更改均可更改)
PS:在这种情况下,Jcombobox的任何替代方案也将受到赞赏。

I need to make a JComboBox that is filled with JRadioButtons as its entries. So it looks like a drop down box that has several JRadioButtons in it that can be chosen. So I used the following code :

JComboBox<JRadioButton> deg=new JComboBox();
DefaultComboBoxModel<JRadioButton> degModel=new DefaultComboBoxModel<>();
degModel.addElement(new JRadioButton("This Button));
deg.setModel(degModel);

So naturally, I would expect a drop down menu of JRadioButtons but instead I happen to see something like this :

enter image description here

So it seems like for some reason, the entry type of the JComboBox hasn't changed although I tried to set the types to JRadioButtons and it's still trying to make a JComboBox of String datatypes and hence is showing the toString of the mentioned JRadioButton.

I also found this link related to the issue but it's only an option on NetBeans (as far as I know) and it's quite weird how changing a built-in compiler option is related to the functionality of a certain class.

Can anyone help me fix this? Any help would be appreciated!
(I also need the JRadioButton to change isSelected when clicked on)
P.S. : Any alternative to JComboBox in this case is also appreciated.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文