String[] boxOptions = {"1","2","4","8","16","20","40","100","400"};
JComboBox box = new JComboBox(boxOptions);
I had these exact lines of code in my program before, and wasn't getting this error. I did a bit of searching and the results I found are going a bit over my head. Any ideas?
The error is:
JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized
public class JComboBox<E> extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible. A component that combines a button or editable field and a drop-down list. The user can select a value from the drop-down list, which appears at the user's request.
A JComboBox is a component that displays a drop-down list and gives users options that we can select one and only one item at a time whereas a JList shows multiple items (rows) to the user and also gives an option to let the user select multiple items.
u can make ur jcombobox uneditable by calling its setEnabled(false). A JComboBox is unEditable by default. You can make it editable with the setEditable(boolean) command. If you are talking about enabled or disabled you can set that by the setEnabled(boolean) method.
You can use:
JComboBox<String> box = new JComboBox<>(boxOptions);
This happens because JComboBox
is now a generic class.
As of Java 7, generics were introduced into JComboBox component. Maybe you were using Java6 before.
You should add JComboBox<String>
to the second line there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With