JComboBox
Integer Month[]= {1,2,3,4,5,6,7,8,9,10,11,12};
JComboBox jComboBox1=new JComboBox(Month);
jComboBox1.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent event)
{
switch (event.getStateChange())
{
case ItemEvent.SELECTED:
System.out.println("选中" + event.getItem());
break;
case ItemEvent.DESELECTED:
System.out.println("取消选中"+event.getItem());
break;
}
}
});
JComboBox的监听事件,通过 event.getStateChange() 方法来获取是否处于选中某一项的状态,若处于选中状态,则再通过 event。getItem()即可获取选中项。