'Changing datatypes of JComboBox elements

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source