A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
video training course this week in the
Swing / AWT / SWT
jtable and the scrollbar
Joined: Sep 29, 2004
Jan 25, 2005 15:10:00
Has anyone ever programitcally changed their horizontal scrollbar?
I'm using a
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:
scrollPane.remove( oldTable ); Point p = scrollPane.getViewport().getViewPosition(); scrollPane.setViewportView( newTable ); scrollPane.getViewport().setViewPosition(p);
Joined: Mar 30, 2003
Jan 26, 2005 09:53:00
Have you tried using the
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:
Point p = scrollPane.getScrollPosition(); scrollPane.remove( oldTable ); scrollPane.setViewportView( newTable ); scrollPane.setScrollPosition(p);
Hope there's something useful to you there.
I agree. Here's the link:
subject: jtable and the scrollbar
Dynamic JTable column sizing with horizontal toolbar
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015