我想同時滾動兩個Jtables。每個JTable放置在JScrollpane上,並且兩個JScrollpanes都設置在JSplitpane上。這裏滾動的relöevant代碼:Simultaniously滾動2個JTables?
teststepScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
rerouteScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
teststepScrollPane.getVerticalScrollBar().setModel(
rerouteScrollPane.getVerticalScrollBar().getModel());
........
public void setTeststepTableFocus(final int teststep) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (teststep <= teststepTable.getModel().getRowCount() - 1){
teststepTable.setRowSelectionInterval(teststep, teststep);
teststepTable.scrollRectToVisible(new Rectangle(teststepTable.getCellRect(teststep, 0, true)));
}
}
});
}
可悲的是它根本不起作用。有任何想法嗎?謝謝你的幫助。