• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree + JList in JScrollPane - Out of Sync

 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm building a UI that looks somewhat like a gantt chart.

How I achieved this look was to have a JScrollPane in my main window frame. I set the viewport view to be a JList and the row header view to be a JTree. I have successfully managed to coordinate the expanding/collapsing of JTree nodes with the showing/hiding of JList items.

I have two problems. Assume both the JTree and JList require more display space than the scroll pane provides and therefore there is a scroll bar.

(1) When I scroll using the scroll bar, my JList repaints itself correctly but my JTree does not. For example, if I scroll down the list, each item moves up but the last item displayed mimics one before it. Obviously, the default scroll pane support is not enough.

- Can my JTree be a listener to something? What might that be?

(2) When I expand/collapse a tree node, sometimes it repositions the JTree in the row header panel. This is a problem because now my rows are out of sync.

- Is there a way I can disable the JTree from doing this?
- If not, is there a way I can figure out how much it scrolled and then scroll it back? I'm afraid if I were to notify the scroll pane and ask it to scroll that much, it would only scroll the JTree again.

Any and all help is greatly appreciated!
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer to (2):

setScrollsOnExpand(false);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic