Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Adding multiple JTree Components to a JScrollPane

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,



In the above code shortCutPane is a JScrollPane and the getFileTree(path) returns a JTree. No problems occurs when I call this statement only once .The JTree component get added to the ScrollPane. But when I call this statement again at runtime the new JTree replaces the existing ones where originally I want to keep all of them on the ScrollPane.

How can I add multiple JTree components to a ScrollPane at runtime ?

Any Help would be much appreciated .Thank you !
 
Saloon Keeper
Posts: 13852
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add all your JTrees to a separate container, and add that container to the JScrollPane.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to our Swing / AWT / SWT / JFace forum, which seems more appropriate and where your question is more likely to get you a useful response.

Edit: Just to clarify, I did not mean to imply that the above response is in anyway not useful, that was simply a matter of unlucky timing.
 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Stephen for the quick reply !

I tried with Jpanel without any luck ! It didnt work for me ! But then I came across the concept of this "Box" container where we can create a Box using the static method createHorizontalBox(); Now It is working fine except for the fact that I cannot control the width of the Box.When I have some long names as the nodes in a Jtree Box fails to show the full name. Can anyone give me a better way to do it ? is it possible using a JPanel ?

Thanks in advance!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want all the JTrees to be the same size, a JPanel with a GridLayout(0, 1) may be a better option than a Box.

Don't forget to revalidate() and repaint() a visible container after any components are add()ed or remove()d.
 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Darryl ! It helped!!
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic