• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Adding a node to a JTree at user command

Hello,
  I have created a JTree without any node. The tree is blank. The user has say create node then comes a dialog where the user has to enter the number and when he says ok then this number should be created as a node there. And since the tree is empty i am getting is a create icon which i want it to be removed.
So what i need is
1) Node should be created at usercommand
2) When the empty tree is created then the icon created should be removed the tree should be blank when i start my gui.

My code is as follows.
DefaultMutableTreeNode node = new DefaultMutableTreeNode("");
DefaultTreeModel tModel = new DefaultTreeModel(node);
JTree tree = new Jtree(tModel);

So this code creates an empty JTree with a create icon as the root element which should be removed

and when the user presses the ok button of the dialog the value in the dialog box should be used to create a tree.

Thanks in advance


regards,
said
0
saidreddy
Asked:
saidreddy
  • 2
  • 2
  • 2
  • +1
1 Solution
 
girionisCommented:
0
 
zzynxSoftware engineerCommented:
0
 
zzynxSoftware engineerCommented:
The paragraph "Dynamically Changing a Tree"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
girionisCommented:
0
 
objectsCommented:
call the following once you have created your new root node:

tModel.setRoot(newnode);
0
 
saidreddyAuthor Commented:
HI
  I have used the command tModel.setRoot(newNode) to set the root element.
Now i need to check whether the root element is empty or not and which i have done i am checking this with a if condition whether the root is empty or not if it is empty then the number i am entering in the dialog box is set as root element. This works fine with me. BUt when i say create node again after the root node has been created and enter a new number it is creating a node as a child to the root element which i do not want to it should create as a normal parent element in the same line as the root element.


For example i say create node 4587
1234(root element)
4587

but not as
1234
----4587

regards
said
0
 
saidreddyAuthor Commented:
hi all,
  I did find a solution finally and thanks all for all your help.

thanks

reg,
said
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now