• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JTree + JList in JScrollPane - Out of Sync

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer to (2):

setScrollsOnExpand(false);
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic