开发者

JScrollBar programmatically

How can I move programmatically a JScrollBar based on amou开发者_如何转开发nt of wheel mouse rotation?


you can use the setValue method of the JScrollBar to set the position of the scroll bar.

Alternatively you can use the methods of the Model behind the JScrollBar; example: bar.getModel().setValue(position).

You can use the getMinimum and getmaximum methods of the JScrollBar (or from the Model) to check the valid values for setValue.

The Javadoc should help more: JScrollBar


The type of scrolling that occurs, either WHEEL_UNIT_SCROLL or WHEEL_BLOCK_SCROLL, is platform dependent. The amount that the mouse wheel scrolls is also platform dependent. Both the type and amount of scrolling can be set via the mouse control panel for the platform.control panel for the platform.

From here


Try this:

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜