Get tree selected element as a string
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Get tree selected element as a string

  1. #1
    Join Date
    Nov 2011
    Posts
    189

    Smile Get tree selected element as a string

    Im making this program that contains a tree. The tree has a root called
    Projects. Inside that there's a number of nodes representing folders.
    Inside that theres a number of leaves representing text files.
    How to get the name of the ancestor node and leaf as a string so i can
    Assemble them in such manner to create a filepath?
    Oh yes.. The selection type of the tree has to be single_selection
    I found quite some turorials on the web but none converrted the node and leaf
    To a string...
    Thanks a lot

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: Get tree selected element as a string

    There are two approaches you can take:

    1. Store the file name or a File object in the leaf node so you can get the value directly from the selected node and thus you don't need to reassemble the path.

    2. Call get JTree's getSelectionPath() method to get the TreePath of the selected node and then calls it's getPath() method to get an array of the nodes from the root node up to and including the selected node. Iterate over this array and get each node's name to build your path as you go.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Nov 2011
    Posts
    189

    Re: Get tree selected element as a string

    got it, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center