Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JComboBox Warning preventing opening the design page in eclipse

OK i am using eclipse and its GUI editor and i have a string like this:

public static String[] blah = {"Blah", "Blah", "Blah", "Blah"};

and a JComboBox like this:

JComboBox comboBox = new JComboBox(blah);
    comboBox.setBounds(10, 56, 312, 37);
    contentPane.add(comboBox);

The combobox uses the string above to get its data but when i enter in "blah" to the combobox it has this error...

Type safety: The constructor JComboBox(Object[]) belongs to the raw type JComboBox.    References to generic type JComboBox<E> should be parameterized

it works if i run it because it is only a warning but it is annoying because it wont let me enter design mode unless i make it a comment. design mode gives this error...

INVALID SOURCE. No Constructor Binding. ---  new JComboBox(locations) is not valid source for component creation, it references not existing constructor. 

so i would like to know if there is any other way to overcome this issue

like image 407
Lucas_F98 Avatar asked Jan 13 '12 02:01

Lucas_F98


1 Answers

// comboBoxTraceModeSelection = new JComboBox<TraceMode>(TraceMode.values());
   comboBoxTraceModeSelection = new JComboBox<TraceMode>();
   comboBoxTraceModeSelection.setModel(new DefaultComboBoxModel<TraceMode>
(TraceMode.values()));

This is a workaround for when using enum in a JComboBox (with WindowBuilder on Eclipse 3.7.2 for java 6). Yes, it does seem to be related to Java generics for objects that are a bit out of the ordinary (enum, String, etc). TraceMode is a custom enum. The commented-out line causes the same error as that of the original poster. This is a WindowBuilder issue, not an Eclipse or Java issue.

like image 112
user2060864 Avatar answered Sep 28 '22 04:09

user2060864