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.
In Netbeans 7.2 you can click on Code section for JComboBox, and then write type into "Type Parameters", in your case: <String>
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With