expanding a Jtree...

6

6e

I am trying to expand a Jtree to the newly added node... however I
can't seem to make it happen.

I've tried a number of things which I listed below, all of these were
tried seperately and together, however the Jtree still does not expand
:(

I also tried to use invalidate and repaint and validate to refresh the
screen, nothing seems to happen...

this is what I have tried so far...

this.fireTreeExpanded(new TreePath(mtnNode.getPath()));

this.expandPath(new TreePath(parentNode.getPath()));

this.scrollPathToVisible(new TreePath(mtnNode.getPath()));

any ideas?
 
B

Branko Kaucic

6e said:
I am trying to expand a Jtree to the newly added node... however I
can't seem to make it happen.

I've tried a number of things which I listed below, all of these were
tried seperately and together, however the Jtree still does not expand
:(

I also tried to use invalidate and repaint and validate to refresh the
screen, nothing seems to happen...

this is what I have tried so far...

this.fireTreeExpanded(new TreePath(mtnNode.getPath()));

this.expandPath(new TreePath(parentNode.getPath()));

this.scrollPathToVisible(new TreePath(mtnNode.getPath()));

any ideas?

See the lines below, they will help you. Let treeMenu be of type JTree.

// you will need this when you access children nodes
TreeModel TM = treeMenu.getModel();

// path to current selected node
TreePath TP = treeMenu.getSelectionPath();

// object of last selected node
Object O1 = TP.getLastPathComponent();

// first children of O1
Object O2 = TM.getChild(O1, 0);

// full path to some children inside node that is represented with TP
TreePath TP2 = TP.pathByAddingChild(O2);

// select the node that is represented by path TP2
treeMenu.setSelectionPath(TP2);

// expand selected row
int[] Rows = panelMenu.treeMenu.getSelectionRows();
panelMenu.treeMenu.expandRow(Rows[0]);

Note that you also have expandPath(TreePath) method.

B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top