0

I want to implement the JTree code into my custom style as shown in figure bellow. I want to design a JTree to be editable on real-time and dynamically store the data into a database.

When I want to add the child, as can be seen on figure, I want to choose from optiosn and make my JTree produce a child node as required.

When I add new node, enter the name and press "ENTER" then it should be saved as it is. So, I want my JTree to produce nodes as per requirement when needed and can be deleted from drop down menu when mouse is clicked on add_icon.

So, anybody please can u help me design my own module or API for such a JTree. please please. this is to be implemented on my project. So, need help very soon. I am doing my project on Netbeans 8.0.2 under swing application.

Jtree Implementation model

Community
  • 1
  • 1
ksodari
  • 67
  • 8

1 Answers1

2

I can offer you add a button to each node of your JTree. It's possible if you redefine TreeCellRenderer and then attach it to JTree:

JTree tree = new JTree(rootNode);
CellRendererWithButton renderer = new CellRendererWithButton();
tree.setCellRenderer(renderer);

Here you can find an example how create your own CellRendererWithButton.

0xFF
  • 585
  • 1
  • 6
  • 22
  • yeah kind of fine but I want little more flexible. I want to make a module which will produce child node when clicked on add button. I am very very beginner and I didn't completely understand how to add a button to each node on jtree. cant we edit the same jtree available on swing framework. can you please help me out with actual codes to do so. Thanks – ksodari Aug 26 '15 at 09:21
  • to be more clear, how i want to implement is that we should be able to dynamically add the child node from user interface and when the the data is inserted and pressed ENTER button then store that data ta database instantly and show on the tree at the same spot where user insert the node. – ksodari Aug 26 '15 at 12:16