Babu R
Babu R

Reputation: 1035

how to Identify the root child nodes?

how to identify is this node is child of root node in Jtree in java swing. Ex:

Root
  |> Parent1
       |> Child1
  |> Parent2
       |> Child 2
       |> Child 3

Here i ll select any one node in that i want to know is the child of root node.

Upvotes: 1

Views: 488

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

Look at the TreeNode API and you'll find the getParent() that will get your node's parent node. If the parent is null -- you're at the root.

You can also call getRoot() on the the JTree's model that will return the root node. Check the TreeModel API for more on this.

Upvotes: 3

Related Questions