e783. 监听对JList中项双击和三击
Posted borter
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了e783. 监听对JList中项双击和三击相关的知识,希望对你有一定的参考价值。
// Create a list
String[] items = {"A", "B", "C", "D"};
JList list = new JList(items);
// Add a listener for mouse clicks
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
JList list = (JList)evt.getSource();
if (evt.getClickCount() == 2) { // Double-click
// Get item index
int index = list.locationToIndex(evt.getPoint());
} else if (evt.getClickCount() == 3) { // Triple-click
// Get item index
int index = list.locationToIndex(evt.getPoint());
// Note that this list will receive a double-click event before this triple-click event
}
}
});
Related Examples |
以上是关于e783. 监听对JList中项双击和三击的主要内容,如果未能解决你的问题,请参考以下文章
UITapGestureRecognizer - 检测双击或三次轻击?