• Post Reply Bookmark Topic Watch Topic
  • New Topic

About JScrollPane

 
vladislav peichev
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to add two JTree components inside a JScrollPane so that the whole space of the pane is covered by the trees regardless expanded or collapsed?
I am using null layout in my JDialog.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a null layout, period. I'd probably go for a BorderLayout with a JSplitPane containing the two JScrollPanes with the JTrees.
 
vladislav peichev
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i need both trees to be inside the same JScrollPane see attached image. Is there a way to do so?
img.png
[Thumbnail for img.png]
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use use a single JTree with two roots?
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously a single JTree can have only one root. However, that root can be a dummy root which contains just two children - the "actual" roots. Let the JTree hide the root (setRootVisible(false)) and you get the same effect.

I'd probably still use a vertical JSplitPane though, as that way a) you can show that the two trees are actually different, and b) you can have individual scrolling for both trees. If you let the JSplitPane's slider be movable as well you give the user even more control on what he can see at the same time.
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Errr.... yes, that's what I meant
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!