正如标题所说......我希望 JList 中的项目只有在双击时才会被“选中”。实现这种行为的最佳方法是什么?
问问题
4369 次
1 回答
1
你可以尝试这样的事情:
JList list = new JList(dataModel);
...
MouseListener mouseListener = new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2) // double click?
{
int posicion = list.locationToIndex(e.getPoint());
list.setSelectedIndex(posicion);
}
else if (e.getClickCount() == 1) // single click?
list.clearSelection() ;
}
};
list.addMouseListener(mouseListener);
告诉我这是否有效......我无法在这里测试它。
于 2010-05-06T18:55:15.040 回答