File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes jtable and the scrollbar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jtable and the scrollbar" Watch "jtable and the scrollbar" New topic

jtable and the scrollbar

jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
Has anyone ever programitcally changed their horizontal scrollbar?

I'm using a JTable in a scrollPane and I need to take three simple steps:

1. get the current position of the horizontal scroll bar
2. recreate the table with new data (not a problem)
3. reposition the scrollbar on the new table to the same position as the old table

Can anyone give me an idea how to get the horizontal scrollbar position?

I tried this approach but haven't had much luck:

Andy Nimmo

Joined: Mar 30, 2003
Posts: 14

Have you tried using the ScrollPane method

setScrollPosition( int x, int y )

You can use it with the Point instance that you've already created in your example code:

setScrollPosition( Point p )

If I had the time I would try this out myself and give you a definitive answer. Try dropping the references to viewPort as well.

Might also be worth getting the scroll position BEFORE you remove the object whose scroll position you're interested in, just a thought.

So try this:

Hope there's something useful to you there.

I agree. Here's the link:
subject: jtable and the scrollbar
It's not a secret anymore!