chrish chrish - 1 year ago 132
Java Question

Java swing JComboBox can't be parametrized

Eclipse IDE showing error on Jcombobox which says that JcomboBox can't be parametarized
eg :something like line showing below

private final JComboBox<LaborHelper> labourname = new JComboBox<LaborHelper>();

here my project execution environment is javaSE1.6

Answer Source

Look at the java 1.6 documentation for JComboxBox, the class JComboxBox is not a generic class for Java 1.6.

It takes an array or a vector of objects as choices for the users and displays them by calling the toString method of the objects (so you have to override it if you want to customize the labels).

To access the value that the user selected, you will have to cast the selected item as follows: (LaborHelper)labourname.field.getSelectedItem()

However, this should work with java 1.7+ as JComboxBox became a generic class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download