不多说,上代码。
使用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);
}
}