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?
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?