Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable W/Scrollbar Repainting Problem  RSS feed

 
Robin K
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Folks.
Here's my problem. I have a JTable with a horizontal scrollbar. I refresh the data using a Timer(). When the app first comes up, it's scrolled to the left. If the user is scrolled to the right when the data refreshes, the whole screen is repainted and it ends up scrolled to the left. How do I refresh the data but stay on the same part of the screen?
I tried using the fireTableDataChanged() method of the table model, but it didn't work.
Can anyone out there help me? Thanks in advance!
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe there is some better method to do it, but, well, try this:
get the value of the horizontal scrollbar, update the value (+ maybe you have to wait until the table gets refreshed and the horizontal scrollbar reset to left), and then set the scrollbar value to the former value (changed by the user).
The "better" possibility might be to either look for a method that sets a flag like "resetScrollbarOnUpdate()" though I haven't stumbled over a simimilar method until now. Or otherwise: Look through the source of javax.swing.JScrollPane, find the method where this behaviour is implemented and write a subclass that behaves as you like.
hope that helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!