Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JTree + JList in JScrollPane - Out of Sync

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):

    Bookmark Topic Watch Topic
  • New Topic