Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetBeans - JComboBox warning - missing type arguments for generic class JComboBox<E>

I am using NetBeans IDE 7.1.2. When I compile my application I get the following warning:

warning: [rawtypes] found raw type: JComboBox city = new javax.swing.JComboBox(); missing type arguments for generic class JComboBox where E is a type-variable: E extends Object declared in class JComboBox

So, I guess I have to declare the JComboBox as:

JComboBox<String> city = new JComboBox<String>();

But how do I do this in NetBeans, using the Matisse (Swing GUI Builder)? Please help.

like image 726
jadrijan Avatar asked Aug 09 '12 15:08

jadrijan


2 Answers

In Netbeans 7.2 you can click on Code section for JComboBox, and then write type into "Type Parameters", in your case: <String>.

like image 71
kabot Avatar answered Nov 17 '22 02:11

kabot


Java 7 introduced generics to the JComboBox. One solution to your problem would be to ust Java 6.

I'd bet the latest version of Netbeans (7.2) will have a solution for this (although I'm not positive).

Otherwise, if I remember right, you can view the code generated by Netbeans. If so, you may be able to add the generic arguement yourself. It's been many months since I tinkered with Netbeans though...

Also, if the Netbeans allows you to, you can add the @SupressesWarnings annotation above the JComboBox declaration (or even above the class declaration, although that changes it's scope). It would be something like this:

@SuppressWarnings("rawtypes")
JComboBox city = new JComboBox();

There are lots of options, but Netbeans may hold you back from implementing some of them.

like image 1
Nick Rippe Avatar answered Nov 17 '22 00:11

Nick Rippe