我有一些行的Jtable。如果我对某些行进行选择,则每次调用ViewModel
(对于每行选择)。有什么方法可以避免这些多次调用,因为如果我选择10000行就会减慢进程的速度
显示行选择的代码
addListSelectionListener
for (int i = 0; i < sArray.length; i++)
{
// int viewindex = mTableForActionListener.getRowSorter().convertRowIndexToView(i);
mTableForActionListener.addRowSelectionInterval(sArray[i].intValue(), sArray[i].intValue());
}
是mDocListTable
的实例。调用它的代码
mTableForActionListener
答案 0 :(得分:1)
解决方案1:
在for循环之前删除侦听器,并在for循环之后将其添加回来。
ListSelectionListener listener = new ListSelectionListener()
{
@Override
public void valueChanged(ListSelectionEvent e)
{
handle_TableSelection(e);
}
};
mDocListTable.getSelectionModel().removeListSelectionListener(listener);
for (int i = 0; i < sArray.length; i++)
{
mTableForActionListener.addRowSelectionInterval(sArray[i].intValue(), sArray[i].intValue());
}
mDocListTable.getSelectionModel().addListSelectionListener(listener);
// add some code here to deal with the new selections in the table.
解决方案2:
在ListSelectionEvent
中,检查是否还在进行调整。
mDocListTable.getSelectionModel().addListSelectionListener(new ListSelectionListener()
{
@Override
public void valueChanged(ListSelectionEvent e)
{
if(e.getValueIsAdjusting()) return;
handle_TableSelection(e);
}
});