Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding multiple JTree Components to a JScrollPane  RSS feed

 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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 !
 
Stephan van Hulst
Saloon Keeper
Posts: 7804
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add all your JTrees to a separate container, and add that container to the JScrollPane.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the reply Darryl ! It helped!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!