更改Jcombobox元素的数据类型
我需要制作一个装有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 :
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论