Java List双击事件
1. 定义一个MouseListener;
2. 在mouseListener中增加mouseClicked事件;
3. 由MouseEvent的getSource()获得List对象;
4. 由List的getSelectedIndex()事件获得点击项的Index;
5. 根据Index,用List的getItem()方法获得点击项;
6. 最后,用addMouseListener()把定义的MouseListener增加到List。
// 双击鼠标事件 MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { List theList = (List) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.getSelectedIndex(); if (index >= 0) { String s = theList.getItem(index); } } } }; lstRoster.addMouseListener(mouseListener);