如何根据滚轮鼠标的旋转量以编程方式移动JScrollBar?
发布于 2010-09-21 17:52:00
可以使用JScrollBar的setValue方法设置滚动条的位置。
或者,您可以在JScrollBar后面使用模型的方法;例如:bar.getModel().setValue(position)。
您可以使用JScrollBar的getMinimum和getmaximum方法(或从模型中)检查setValue的有效值。
Javadoc应该能提供更多帮助:JScrollBar
发布于 2010-09-21 17:17:51
发生的滚动类型( WHEEL_UNIT_SCROLL或WHEEL_BLOCK_SCROLL )取决于平台。鼠标滚轮滚动的数量也取决于平台。滚动的类型和数量都可以通过平台的platform.control面板的鼠标控制面板进行设置。
来自here
发布于 2017-02-10 12:27:33
试试这个:
private void scrollToBottom() {
int tamanio = scrollPane.getVerticalScrollBar().getMaximum();
scrollPane.getVerticalScrollBar().getModel().setValue(tamanio);
}
private void scrollToTop() {
scrollPane.getVerticalScrollBar().getModel().setValue(0);
}
private void scrollToNext() {
int posicion = scrollPane.getVerticalScrollBar().getModel().getValue();
int altura = scrollPane.getHeight();
scrollPane.getVerticalScrollBar().getModel().setValue(posicion+altura);
}
private void scrollToBack() {
int posicion = scrollPane.getVerticalScrollBar().getModel().getValue();
int altura = scrollPane.getHeight();
scrollPane.getVerticalScrollBar().getModel().setValue(posicion-altura);
}https://stackoverflow.com/questions/3758785
复制相似问题