package FinalData;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class JCoboBoxModelTest extends JFrame{
JComboBox<String>jc=new JComboBox<>(new MyComboBox());
JLabel jl=new JLabel("请选择证件");
private Container cp;
public void JComboBoxModelTest(){
cp.setLayout(new FlowLayout());
cp.add(jl);
cp.add(jc);
}
public static void main(String[] args) {
}
class MyComboBox extends AbstractListModel<String>implements ComboBoxModel<String>{
String selecteditem=null;
String[] test= {"身份证","军人证","学生证","工作证"};
public String getElementAt(int index){
return test[index];
}
public int getSize() {
return test.length;
}
public void setSelectedItem(Object item) {
selecteditem=(String)item;
}
public Object getSelectedItem() {
return selecteditem;
}
}
}