• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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.
 
grapes are vegan food pellets. Eat this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic