• Post Reply Bookmark Topic Watch Topic
  • New Topic

add dynamic folders to JTree

 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you very much mKorbel, I didn't know about Accordion and Ribbon, you gave me nice idea.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!