不多说,上代码。
使用getViewport()就好。
String newProd = JOptionPane.showInputDialog(SettingFrame.this, "Please enter the name of queue you want to monitor.");
if(newProd != null && newProd.trim().length() > 0) {
SettingFrame.this.prodListModel.addElement(newProd);
int endIndex = SettingFrame.this.prodListModel.size() - 1;
Point point = SettingFrame.this.listProducts.indexToLocation(endIndex);
selectJListIndex(SettingFrame.this.listProducts, endIndex);
SettingFrame.this.scrollPaneProd.getViewport().setViewPosition(point);
}
}

本文介绍了一种在Java Swing中通过getViewport()方法将视口定位到新添加列表项的技术。当向列表中添加新元素后,可以通过获取列表视口的位置并设置为新元素的位置来实现滚动效果。
6202

被折叠的 条评论
为什么被折叠?



