12

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.

jadrijan
  • 1,438
  • 4
  • 31
  • 48

2 Answers2

17

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

KatieK
  • 13,586
  • 17
  • 76
  • 90
kabot
  • 171
  • 1
  • 3
  • 4
    This helped, just one small improvement to clarify how to get to the code section: right-click the JComboBox, choose _Properties_, select the _Code_ section (at the top of the properties window). _Type Parameters_ is close to the top. – Christian Garbin May 12 '13 at 16:58
  • @chr and remember to write the type parameter _including_ the angle brackets. – Thomas Ahle Aug 01 '14 at 11:37
1

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.

Nick Rippe
  • 6,465
  • 14
  • 30
  • Nick I tried to change the code to: city = new javax.swing.JComboBox(); (NetBeans does not allow me to change the declaration variables therefore my city is defined as private javax.swing.JComboBox city;). When I did this I get the following warning: redundant type arguments in new expression (use diamond operator instead). – jadrijan Aug 09 '12 at 16:03
  • 1
    I'm not sure you'll be able to get around the warning then without downgrading your Java version or updating your Netbeans IDE. Fortunately, it's just a warning so it won't affect your actual code. If it bothers you, you can try adding this line above your declaration: `@SuppressWarnings("rawtypes")` I'll add this to the answer as well. I don't know of a way to turn compiler warnings off in Netbeans - someone else may know. – Nick Rippe Aug 09 '12 at 19:15
  • Thank you very much Nick. At least now I know that I am not doing anything wrong as per coding. I hope this is fixed in the v7.2, I haven't tried it yet, waiting for oracle to release it with JDK. – jadrijan Aug 10 '12 at 12:56