bobby1112
08-12-2009, 16:31
salve ragazzi sono all' inizio con java per esercizio devo gestire un JCombobox con un ComboBoxModel per esempio devo visualizzare un'array di stringhe attraverso un ComboBoxModel
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Frame extends JFrame {
private JPanel mioPannello =new JPanel();
public Frame()
{
ComboModel model=new ComboModel();
JComboBox combo=new JComboBox();
combo.setModel(model);
mioPannello.add(combo);
this.setSize(300,350);
this.setVisible(true);
this.setContentPane(mioPannello);
}
public static void main(String[] args) {
Frame f=new Frame();
}
}
questa e la mia classe principale invece la classe ComboModel come dovrebbe essere implementata
public class ComboModel extends AbstractListModel implements ComboBoxModel{
@Override
public Object getSelectedItem() {
// TODO Auto-generated method stub
return "Rino";
}
@Override
public void setSelectedItem(Object anItem) {
// TODO Auto-generated method stub
}
@Override
public Object getElementAt(int index) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return 0;
}
}
Grazie a tutti
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Frame extends JFrame {
private JPanel mioPannello =new JPanel();
public Frame()
{
ComboModel model=new ComboModel();
JComboBox combo=new JComboBox();
combo.setModel(model);
mioPannello.add(combo);
this.setSize(300,350);
this.setVisible(true);
this.setContentPane(mioPannello);
}
public static void main(String[] args) {
Frame f=new Frame();
}
}
questa e la mia classe principale invece la classe ComboModel come dovrebbe essere implementata
public class ComboModel extends AbstractListModel implements ComboBoxModel{
@Override
public Object getSelectedItem() {
// TODO Auto-generated method stub
return "Rino";
}
@Override
public void setSelectedItem(Object anItem) {
// TODO Auto-generated method stub
}
@Override
public Object getElementAt(int index) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return 0;
}
}
Grazie a tutti