This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I use same tree is 2 seperate split panes  RSS feed

 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers

I'm relatively new to Swings especially the Tree part of it...

I'm trying to reuse a tree.. I create a tree with a bunch of nodes; specify a tree model; register listeners; work on selections...

Now can I use this same in another splitPane.. i tried doing that but I can see only 1 tree? why is this happening?

Can I add the same tree to 2 different Split Panes...

if so how?

if not... why not?

Thanks
R
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, Swing does not allow you to use the same object on 2 different containers. What you can do is create 2 instances of your JTree and they should be able to share the model.
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sheriff

Essentially you are trying to say same Model(treeModel ) but different Views (tree). A tree has 2 models right? (Can I share the same selectionModel for 2 different trees)?

[In my case tree being child component and its parent is the Scroll Pane] ... All I'm trying to do is share a childcomponent between 2 parents.

what is the reason behind such a development methodlogy? Isn't it reducing our reuse options?

Am I missing something really obvious here?

Thanks
Ravi
[ December 23, 2004: Message edited by: Ravi Shankar Sathish ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A component can only have 1 parent. I do not know the ins and outs of why, but that is how it works.

Yes, 2 trees and one tree model. Both trees can also share the same listener which isn't a model. It's just a selection listener.

Out of curiosity why do you need 2 trees that appearntly do the exact same thing?
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg & fellow Ranchers

Sorry for not replying earlier... Its a bit abnormal requirement...

My trees are tied to Tabs... Tabs serving different displaying different flavors of same data...

Thanks for asking the question though... I am guessing I would rather keep the Tree constant and change just the data flavors in the tab... instead of rebuilding the whole new tab...when half of it is reusable

On second thoughts...even though both the trees share same tree Model... their behaviors are determined based on their parent Tab Views...

essentially TreeModel is same but Selection Listeners differ

I am sure the design needs a redo for the problem I'm trying to solve

Thanks a ton
R
[ December 28, 2004: Message edited by: Ravi Shankar Sathish ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!