JComboBox Warning on preventing the opening of a design page in eclipse

OK I use eclipse and its graphical editor, and I have a line like this:

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

and JComboBox:

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

The combobox uses the line above to get its data, but when I enter the "blah" in the combo box, 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 will not allow me to 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 another way to overcome this problem.

+5
source share
3 answers

, WindowBuilder generics JComboBox<E> whitch jre7.

, , jre6 → Java → JRE , "JavaSE-1.6" → → Java.

, java 7, , , Windowbuilder generics.

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

JComboBox ( WindowBuilder Eclipse 3.7.2 java 6). , , Java , (enum, String ..). TraceMode - . , . WindowBuilder, Eclipse Java.

+8

, OP , 3 : D, , , :

, , , ComboBoxModel JComboBox.

Defining the first model (for example, using DefaultComboBoxModel), adding the necessary elements, and then passing the above model to the JComboBox constructor, does not lead to this error and works fine.

eg.

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

DefaultComboBoxModel<String> comboModel = new DefaultComboBoxModel<String>(blah);

JComboBox comboBox = new JComboBox(comboModel);`

Pretty concise and readable, I think :)

+2
source

All Articles