Adding a node to a JTree at user command

  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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSoftware engineerCommented:
zzynxSoftware engineerCommented:
The paragraph "Dynamically Changing a Tree"
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
saidreddyAuthor Commented:
  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)

but not as

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


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.