Bick
Bick

Reputation: 18521

Swing: JPanel on JScrollPane - how to jump and move focus to show a specific part of the panel

I have a very long jpanel on a jscrollpane.

I want to be able to jump to a location in the panel. is there a way to jump to a specific point in the pane?

Setting the horizontal scrollbar value is not enough Is there a way to mark a position and jump to it (rather than giving X,Y)? Thanks.

Upvotes: 0

Views: 239

Answers (1)

Walter Laan
Walter Laan

Reputation: 2976

See scrollRectToVisible for scrolling. Not sure what you mean with "mark a position" but if you want to scroll to for example a text field that is a (direct) child of the panel than you would do:

panel.scrollRectToVisible(textField.getBounds());

Upvotes: 3

Related Questions