我当前有两个 JList 实例,一个是 priceList
,另一个是 nameList
。当它们滚动时,我希望它们一起滚动,因为它们是并排的。目前,我能找到的唯一方法是使用此代码让它们在用户选择时突出显示相同的索引结果。
priceList.setSelectedIndex(nameList.getSelectedIndex());
priceList.ensureIndexIsVisible(nameList.getSelectedIndex());
还有其他可行的方法吗?
最佳答案
您可以尝试从滚动 Pane 滚动条附加 BoundRangeModel 并将其应用于其他。
BoundedRangeModel model = scrollPane1.getHorizontalScrollBar().getModel();
scrollPane2.getHorizontalScrollBar().setModel(model);
这应该会导致两个滚动条自动相互更新
关于java - 让两个JList同时滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11537059/