Reputation: 41
I add listselectionlistener when i clicked on a tab
table1 = new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
action(e);
}
};
ListSelectionModel SM = table1A.getSelectionModel();
SM.addListSelectionListener(table1);
SM = table1B.getSelectionModel();
SM.addListSelectionListener(table1);
When i clicked on the row of the table, the action(e) function fired many times.
private void action(ListSelectionEvent e)
{
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.getValueIsAdjusting())
{
// nothing
}
else
{
// my action here
}
}
The action(e) should fired twice, once is when mouse clicked, once is when mouse release. I had use the getValueIsAdjusting() to counter the mouse click, so my action should be run once. But, my action run many times. i can see this because i need to put a busy dialog inside my action.
Upvotes: 2
Views: 1718
Reputation: 382
You need to set "value is Adjusting" to true.
SM.setValueIsAdjusting(true);
Please rename SM to sM because a java attribute should be begin with small letter.(Java Convention)
Upvotes: 1