Generic JComboBox

R

RedGrittyBrick

Re: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6303622

Would a Generic JComboBox need to be any more complex than the
following?


public class GComboBox<T> extends JComboBox {

public GComboBox(List<T> list) {
super(list.toArray());
}

public GComboBox(T[] items) {
super(items);
}

@SuppressWarnings("unchecked")
@Override
public T getSelectedItem() {
return (T) super.getSelectedItem();
}

}


The above can be used generically thus:
List<Dog> dogList = new ArrayList<Dog>();
...
GComboBox<Dog> dogBox = new GComboBox<Dog>(dogList);
...
Dog chosenDog = dogBox.getSelectedItem();

Presumably generifying JComboBox can't be this easy?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top