我添加listselectionlistener當我一個標籤列表選擇偵聽器的valueChanged發射的2倍以上
table1 = new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
action(e);
}
};
ListSelectionModel SM = table1A.getSelectionModel();
SM.addListSelectionListener(table1);
SM = table1B.getSelectionModel();
SM.addListSelectionListener(table1);
當我點擊了表的行上點擊,行動(五)功能解僱了很多次。
private void action(ListSelectionEvent e)
{
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.getValueIsAdjusting())
{
// nothing
}
else
{
// my action here
}
}
動作(e)應該發射兩次,一次是鼠標點擊,一次是鼠標釋放。我使用getValueIsAdjusting()來對抗鼠標點擊,所以我的動作應該運行一次。但是,我的行爲運行了很多次。我可以看到這個,因爲我需要在我的動作中放置一個忙碌的對話框。
我想您所想一個'MouseListener'的。 'ListSelectionListener's監聽所選內容的變化,而不是鼠標點擊和釋放。這些可能是非常不同的事情。 – gla3dr 2014-08-30 07:17:28
Well'ListSelectionModel SM = table1A.getSelectionModel(); SM.addListSelectionListener(table1); SM = table1B.getSelectionModel(); SM.addListSelectionListener(table1);'似乎是兩次添加偵聽器! – 2014-08-30 08:45:53
爲了更快獲得更好的幫助,請發佈[MCVE](http://stackoverflow.com/help/mcve)(最小,完整,可驗證示例)。 – 2014-08-30 08:46:14