• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

JTree class

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to retrieve the previous node using JTree class.

I can retrieve the currently selected node using getLastSelectedPathComponent() method

For eg:
TreeNode selArea = (TreeNode)layoutTree.getLastSelectedPathComponent();

Is there any method, that I can retrieve the previous node (last but one).

Your help is very much appreciated. Thanks in advance.
 
Sheriff
Posts: 22715
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using TreeNodes in the JTree? If so, it is not that hard.

First of all, check if the node has a previous sibling:

If it isn't, you have to check the parent's sibling, and then choose the very last (grand)child of that:

Eventually you will find the last node because that will be a leaf.
 
sahitya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way I explained is little bit confusing. I want to retrieve the previously selected node.

Suppose I have A1,A2,A3 and A4 node under A. First I have selected A1 and then I have selected A3. Now I need to get the previously selected node (i.e., A1)

I hope it is understood.

Sample code from my program.
private JTree layoutTree = null;
TreeNode selArea = (TreeNode)layoutTree.getLastSelectedPathComponent();
 
sahitya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way I explained earlier is little bit confusing. Please find the detailed explanation of my problem.

Suppose I have A1,A2,A3 and A4 nodes under A. First I have selected A1 and then I have selected A3 (currently selected). Now I need to get the previously selected node (i.e., A1)

I hope it is understood.

Sample code from my program.
JTree layoutTree = null;
TreeNode layoutNodes = new TreeNode("default");
layoutTree = new JTree(layoutNodes)
TreeNode selArea = (TreeNode)layoutTree.getLastSelectedPathComponent();
//Will retrieve currently selected node

Now I need to retrieve the previously selected node (which may not be previous node).

Please help me. Let me know for any further clarifications.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're just going to have to store that yourself. There isn't anything in the API holding this information for you.
 
sahitya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I do that??
 
Rob Spoor
Sheriff
Posts: 22715
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a TreeSelectionListener. Check out when all of its events are triggered, and what information they contain.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic