File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTree + JList in JScrollPane - Out of Sync Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree + JList in JScrollPane - Out of Sync" Watch "JTree + JList in JScrollPane - Out of Sync" New topic
Author

JTree + JList in JScrollPane - Out of Sync

Kelly Dolan
Ranch Hand

Joined: Jan 08, 2002
Posts: 107
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

Joined: Jan 08, 2002
Posts: 107
Answer to (2):

setScrollsOnExpand(false);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree + JList in JScrollPane - Out of Sync
 
Similar Threads
JScrollPane row header grab-and-drag
Auto Scroll List/Scroll Pane
JTree - expanding nodes
Question regarding JTree
Transparent JTree over gradient background