你试试这个!jlFunctions.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
if (e.isTemporary()) return;
/**---------Handle the jsFunction ListSelectionEvent */
System.out.println("the JComboBox event");
}
});
public void valueChanged(ListSelectionEvent e){
if (e.isTemporary()) return;
/**---------Handle the jsFunction ListSelectionEvent */
System.out.println("the JComboBox event");
}
});
解决方案 »
- 如何判断Map<String, Object>为空?
- 有很多条件时间,在一个map里面.然后通过1定的需求要换算出另外一些时间!不知道这个有人会吗?想半天也想不出怎么写
- 访问控制符protected的定义在这个实例中怎么解释?谢谢
- 请教(new Double("0.0010")).doubleValue() 为 0.0010的问题(double数字精度问题)
- 取数据库中表的复合主键为何没有反应?百思不解!
- 在线送分!!!!!!!!
- 一个郁闷的java函数,高手请进~~~~
- 请教几个小问题,谢谢~~
- 怎么用jb5创建一个corba工程?
- 请教高手:关于URL操作
- 如何用Java 的socket 来实现服务器和客户端的图象交互传输,急盼!!!
- &&&&&做不出来不罢休&&&&&&&&关于Applet的数字签名!我太着急了!!(在线等待!)
up
petList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String petName = (String)cb.getSelectedItem();
picture.setIcon(new ImageIcon("images/" +
petName + ".gif"));
}
});sun的教程:
Combo boxes also generate item events, which are fired when any of the items' selection state changes. Only one item at a time can be selected in a combo box, so when the user makes a new selection the previously selected item becomes unselected. Thus two item events are fired each time the user selects a different item from the menu. If the user chooses the same item, no item events are fired. Use addItemListener to register an item listener on a combo box. How to Write an Item Listener gives general information about implementing item listeners.
JComboBox在选择其中的一项时先发生的是释放它先前选则的那一项,
然后发生的是选择现在选择的那项不过JComboBox好象没有addListSelectionListener方法耶!!!
应该是这样的吧!你这样试试就明白我上面说的了.
JComboBox c=new JComboBox();
c.addItemListener(new ItemListener(){
public void itemStatechanged(ItemEvent event){
int state=event.getStateChange();
String item=(String)event.getItem(),s;
if(event.getStateChange()==ItemEvent.SELECTED) s="123";
if(event.getStateChange()==ItemEvent.DISELECTED) s="456";
System.out.println("the state is:"+s);
}
});看看结果你就明白了.