This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases 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
  • 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

add dynamic folders to JTree

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As shown in layout below JFrame contains JTree and CardLayout panel.
Folder colors1 contains following nodes: blue, violet, red.
By clicking JTree nodes: blue, violet and red CardLayout shows related panel to each node. (These part is done).
___________________________
| Jtree
| |
| colors1 | CardLayout panel
| |
| blue
| violet
| red
|_________________________

Now I w'd like to add folders colors2 [blue,violet,red], colors3[blue,violet,red], colors4[blue,violet,red], ... to JTree by addButton and delete them except colors1 by deleteButton.
And folder nodes: blue, violet, red must be referenced to panel and shown on CardLayout.

But I don't know how to add dynamic folders to JTree.
How can I implement it. Any help is really appreciated.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tai Yo wrote:
But I don't know how to add dynamic folders to JTree.
How can I implement it. Any help is really appreciated.


Check out https://docs.oracle.com/javase/tutorial/uiswing/components/tree.html#dynamic
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- you have to override TreeCellRenderer, to enlarge the gap between nodes, override getPreferredSize for nested JPanel that returns its Dimension properly back to Painter

- Renderers concept in Swing is just an illlusion with very intensive painting, then you have to override mouse events (convert from SwingUtilities) if you want to switch betweens Cards (conflict with colapsing the node)

- don't to use JTree for this idea, search for Java + Swing + Accordion, or Ribbon, there must be two three very good attempts that is settable

__________________________________________________

- why you don't do that, one of good attempts
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much mKorbel, I didn't know about Accordion and Ribbon, you gave me nice idea.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic