• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can I use same tree is 2 seperate split panes

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic