Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized

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
like image 816
tssguy123 Avatar asked Dec 15 '13 15:12

tssguy123


People also ask

What is a JComboBox?

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.

What is the main difference between JComboBox and Jlistbox?

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.

How do I make JComboBox not editable?

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.


2 Answers

You can use:

JComboBox<String> box = new JComboBox<>(boxOptions);

This happens because JComboBox is now a generic class.

like image 142
BobTheBuilder Avatar answered Oct 09 '22 11:10

BobTheBuilder


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.

like image 44
britulin Avatar answered Oct 09 '22 10:10

britulin