How to search a child node in JTree

Hi I am new to swings..
My requirement is I have a Jsplit pane.
I have search button with a text box in one and Jree in another pane.
When I enter a string and hit Search button...It need to search the tree and expand that node highlight it.
can anyone help in getting this done.

public void actionPerformed(ActionEvent e)
  DefaultTreeModel m_model = new DefaultTreeModel(entityRoot);
  DefaultMutableTreeNode node = searchNode(m_searchText.getText());
  JTree m_tree = new JTree(m_model);
  TreePath root = m_tree.getPathForRow(0);
  searchTree(m_tree, root, m_searchText.getText());
private void searchTree(JTree tree, TreePath path, String q)
TreeNode node = (TreeNode)path.getLastPathComponent();
if(node==null) return;
if(node.toString().startsWith(q))
   tree.setScrollsOnExpand(true);
   tree.setSelectionPath(path);
if(!node.isLeaf() && node.getChildCount()>=0)
   Enumeration e = node.children();
   while(e.hasMoreElements())
   searchTree(tree, path.pathByAddingChild(e.nextElement()), q);
}Edited by: EJP on 27/06/2011 09:53: added {noformat}{noformat} tags. Please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How can I remove child node from JTree???

    Hi,
    I would like to remove all the child node of my jtree. For instance I would like to remove the c, d, and e nodes. It's possible to remove all the child node or to remove by her name ("c", "d", and "e"). If yes what is the method that it permit to do.
    A-----
    |
    b-------c
    |
    |--------d
    |
    ---------e
    I use the model : DefaultMutableTreeNode
    Thanks

    There are a couple of ways it can be done. If your tree uses DefaultTreeModel as its TreeModel, you can use removeNodeFromParent(). This will remove the node from its parent and effectively remove its children, too. All nodes removed will be garbage-collected if there are no other references to them.
    If your tree model is not the default tree model, but still uses MutableTreeNode, you can use either remove() or removeFromParent() on the node itself, depending on whether you want to remove the node itself or one of its children.
    On the other hand, your tree may use a model that simply "mirrors" another data structure, in which case you would have to remove the node from the other data structure and have it reflected in the model.

  • How can provide parent-child nodes relation ships?

    how can provide parent-child nodes relation ships?

    I was under the impression that scenegraph is like a JTree. But in JavaFX only leaf node rendering in scenegraph. This situation was confusing my mind. In JavaFX CustomNode must be extending and return a group for custom leaf. If we want to a create parent-child node hierarchy we are create CustomNode that return a group and this group contain an another group,etc. So there is maybe only a way. If you learning to JavaFX first time.This way don't look familiar.

  • Lining up root node and child nodes in JTree

    I have a JTree that has a root node and n child nodes. There are no sub-levels - it is structured just like AOL instant messenger. What I want to do is have the child node icons line up directly under the root nodes text. For example (if you can read this), where "-" denotes the icon:
    - root
    - child
    - child
    Currently it is something like this:
    - root
    - child
    - child
    I have been messing with the setLeftChildIndent( int ) and setRightChildIndent( int ), but they are not doing much...they seem to not want to only move the leaf nodes but all of the nodes, so its not doing exactly what I want.
    Any ideas? In the meantime I'll be looking more into how exactly those indent mutators work.
    Thanks!

    What you want is to do a setRootVisible(false) on the JTree.
    All your child nodes are then your "root level" folders.
    tree.setRootVisible(true):
    +root
    +--child1
    +--child2
    +--child3
    +----child3a
    +----child3btree.setRootVisible(false):
    +child1
    +child2
    +child3
    +--child3a
    +--child3b

  • Read child nodes in Jtree

    Need some help in reading the child nodes in a jTree after a parent node has been selected.
    I've created a Jtree using DefaultMutableTreeNode. When I select a node, I'm able to read the contents of that node but can't figure out how to read all the children beneath it.
    I'm using this code to read the current selected path:
    TreePath tp1 = jTreeTOC.getSelectionPath();
    Object bal_Grp[] = tp1.getPath();
    int iNodeCnt = bal_Grp.length;
    if (iNodeCnt > 1) {
    String sTOCNode = bal_Grp[iNodeCnt-1].toString();
    So my sTOCNode is the selected one, now how do I get the children.
    Any help is appreciated.
    Thanks

    Read the tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#select
    If you use getLastSelectedPathComponent you get back DefaultMutableTreeNode object of the selected node.
    You can use it to get the children of the selected node.

  • How to store multiple child nodes using dbms_xmlstore

    Hi,
    I'm using oracle 10g environment. In DBMS_XMLSTORE package I cannot able to insert the multiple child node value into db table.
    Here I have given the xml value
    <DATAPACKET REQUEST-ID="10001094">
      <HEADER>
        <SEARCH-RESULT-LIST>
          <SEARCH-RESULT-ITEM NAME="Ra-Al-Gul" CONFIDENCE-SCORE="750" BUREAU-ID="893991307899440">
            <IDENTIFIERS>
              <IDENTIFIER IDSOURCE="0001" MATCHED="TRUE"/>
            </IDENTIFIERS>
            <SURROGATES>
              <SURROGATE ID="CH0001" MATCHED="TRUE"/>
              <SURROGATE ID="CH0002" MATCHED="TRUE"/>
              <SURROGATE ID="CH0003" MATCHED="TRUE"/>
            </SURROGATES>
          </SEARCH-RESULT-ITEM>
        </SEARCH-RESULT-LIST>
      </HEADER>
    </DATAPACKET>for this xml data I have created the below table structure
    -- Table create script
    CREATE TABLE xml_insert (datapacket t_response );
    /* Type creation  code  */
    CREATE OR REPLACE TYPE t_response AS OBJECT
      "@REQUEST-ID" VARCHAR2(100),
      header        t_resp_header
    CREATE OR REPLACE TYPE t_resp_header AS OBJECT
      "SEARCH-RESULT-LIST"    t_search_item
    CREATE OR REPLACE TYPE t_search_item AS OBJECT
    ("SEARCH-RESULT-ITEM"      t_search_list);
    CREATE OR REPLACE TYPE t_search_list AS OBJECT
    ("@NAME"           VARCHAR2(300),
    "@CONFIDENCE-SCORE"      VARCHAR2(300),
    "@BUREAU-ID"           VARCHAR2(300),
    IDENTIFIERS           t_search_identifiers,
    SURROGATES           t_search_surrogates
    CREATE OR REPLACE TYPE t_search_identifiers AS OBJECT
    (IDENTIFIER           t_search_IDENTIFIER);
    CREATE OR REPLACE TYPE t_search_identifier AS OBJECT
      "@IDSOURCE"           VARCHAR2(20),
      "@MATCHED"           VARCHAR2(20)
    CREATE OR REPLACE TYPE t_search_surrogates AS OBJECT
    (SURROGATE           t_search_SURROGATE);
    CREATE OR REPLACE TYPE t_search_surrogate AS OBJECT
    "@ID"                VARCHAR2(20),
    "@MATCHED"           VARCHAR2(20)
    CREATE OR REPLACE TYPE tb_search_surrogate AS TABLE of t_search_SURROGATE;
    /and run this block
      DECLARE
      insCtx DBMS_XMLStore.ctxType;
      rows NUMBER;
      xmldoc CLOB :=
    <ROWSET>
    <ROW>
    <DATAPACKET REQUEST-ID="Q10001094">
      <HEADER>
        <SEARCH-RESULT-LIST>
          <SEARCH-RESULT-ITEM NAME="Anis kulam" CONFIDENCE-SCORE="750" BUREAU-ID="893991307899440">
            <IDENTIFIERS>
              <IDENTIFIER IDSOURCE="0001" MATCHED="TRUE"/>
            </IDENTIFIERS>
            <SURROGATES>
              <SURROGATE ID="CH0001" MATCHED="TRUE"/>
              <SURROGATE ID="CH0002" MATCHED="TRUE"/>
              <SURROGATE ID="CH0003" MATCHED="TRUE"/>
            </SURROGATES>
          </SEARCH-RESULT-ITEM>
        </SEARCH-RESULT-LIST>
      </HEADER>
    </DATAPACKET>
    </ROW>
    </ROWSET>';
    BEGIN
      insCtx := DBMS_XMLStore.newContext('xml_check');
      rows := DBMS_XMLStore.insertXML(insCtx, xmlDoc);
      DBMS_XMLStore.closeContext(insCtx);
    END;I got the following error
    Error Messgae :
    ORA-19031: XML element or attribute SURROGATE does not match any in type DOHADEV.T_CRB_SEARCH_SURROGATES
    ORA-06512: at "SYS.DBMS_XMLSTORE", line 78
    ORA-06512: at line 28

    Hi,
    A couple of comments to begin with :
    - Your setup script, test case and error message are not consistent with each other.
    - You've not chosen the easiest road with DBMS_XMLSTORE and nested objects. As pointed out in a previous thread of yours, the whole thing would be far more simple with XMLTable.
    Do you really need to store the data in an object-relational structure at the end, or do you intend to further break it down into relational rows and columns?
    Do you have an XML schema?

  • How to fetch the child Nodes using XNode

    Hi All,
    How to fetch child nodes of XNode object ?
    I am moving my code to .net 3.5 so i was replacing XMLNode to XNode , but i could find any ChildNodes() method.
    Thanks,
    Pallavi

    As such this  is not a  SharePoint related question, even though there are many way to parse the XNode object. 
    One way is,
    XNode an all other are derived from XElement, so you can use Linq to get all children by casting it with XElement, below is a snippet
    XDocument doc = XDocument.Load(""); //Path
    XElement ele = doc.Nodes().First() as XElement;//Just taking the first element as XNode
    foreach (var item in ele.Elements())
    var v = item;
    You can use Full Linq queries to find any node, just for example, below is a snipped to find a node based on a attribute value
    ele.Elements().Where(x => x.Attribute("text").Value == "text");
    get2pallav
    Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

  • How to retrieve a child node's immediate parent node from a tree table?

    Hello
    Hi,
    I have a category_subcategories table, and I would like to know how to construct a sql and sub-sql for retrieving a child node's immediate parent node.
    Here is my first part of the sql, it only returns the node "Flash"'s parent and its grand-parents:
    SELECT parent.category_name, node.lft, node.rgt
    FROM category_subcategories AS node,
    category_subcategories AS parent
    WHERE node.lft > parent.lft AND node.lft < parent.rgt
    AND node.category_name = 'FLASH'
    ORDER BY parent.lft;
    | name |
    | ELECTRONICS |
    | PORTABLE ELECTRONICS |
    | MP3 PLAYERS | |
    how can I modify this query so that it returns Flash' parent - 'MP3 Players'?
    Thanks a lot
    Sam

    Hi,
    This is an Oracle forum. If you're not iusing Oracle, make that clear. Always say what version of your softwate you're using, whether it's Oracle or anything else.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data. Explain how you get those results from that data.
    It looks like you're using the Nested Sets technique for modeling a tree. To get the parents of given nodes, do something like this:
    SELECT        parent.category_name
    ,       node.lft
    ,       node.rgt
    FROM        category_subcategories      node     -- Can't use AS with table alias in Oracle
    ,       category_subcategories      parent
    WHERE        parent.lft      IN (
                        SELECT     MAX (lft)
                        FROM     category_subcategories
                        WHERE     lft     < node.lft
                        AND     rgt     > node.rgt
    AND        node.category_name          = 'FLASH'
    ORDER BY  parent.lft; This should work in Oracle 8.1 and up. (I can't actually test it unless you post CREATE TABLE and INSERT statements for some sample data). You may need to modify the syntax a little for your database.
    785102 wrote:
    Hello,
    I tried to implement the solution as follow:
    mysql> select parent.*
    -> from category_subcategories as parent
    -> having parent.lft =
    -> (select max(parent.lft) from
    -> (SELECT parent.category_name, parent.lft, parent.rgt
    -> FROM category_subcategories AS node,
    -> category_subcategories AS parent
    -> WHERE node.lft > parent.lft AND node.lft < parent.rgt
    -> AND node.category_name = 'Sofa'
    -> ORDER BY parent.lft
    -> )
    -> );
    ERROR 1248 (42000): Every derived table must have its own alias
    mysql>
    But I got an error.
    What is wrong with it?What does the error message say?
    Apparantly, in your system (unlike Oracle), every sub-query must have a name. Try something like this:
    select      parent.*
    from      category_subcategories as parent
    having      parent.lft = (
                   select      max(parent.lft)
                   from     (
                             SELECT        parent.category_name
                             ,       parent.lft
                             ,       parent.rgt
                             FROM        category_subcategories      AS node,
                                    category_subcategories      AS parent
                             WHERE        node.lft      > parent.lft
                             AND        node.lft      < parent.rgt
                             AND        node.category_name = 'Sofa'
                             ORDER BY  parent.lft     -- Is this a waste of effort?
                        )  AS got_name_lft_and_rgt
                  )     AS got_lft
    ;What is the purpose of having the inner sub-query, the one I called got_name_lft_and_rgt?
    Also, in Oracle, an ORDER BY clause in a sub-query doesn;t guarantee that any super-queries will keep that order. Why do you have an ORDER BY clause in the sub-query, and not in the main query?

  • How to reach at a node of JTree : Urgent

    Hay all,
    Plz tell me that how to reach at a particular node in a JTree, whose name is known to you.I have used a DefaultTreeModel to create a tree. As
    deviceTreeModel=new DefaultTreeModel(rootNode);
    tree = new JTree( deviceTreeModel );
    Thanks and Regards,
    Sharad Agarwal

    an inefficient way is to traverse the tree to find the node
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
    public TreeNode getNode(DefaultMutuableTreeNode node, String nodeName){
        if (node.getChildCount() == )
            return null;
         for (Enumeration e = node.childrens() ; e.hasMoreElements() ;) {
             DefaultMutuableTreeNode child = (DefaultMutuanbleTreeNode) e.nextElement();
             if (child.getUserObject.().toString().equals(nodename))
                 return child;
             else
                 getNode(child, nodeName);
    }once you got the node, you can use the
    DefaultTreeModel.insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)

  • How to search in particular node

    hi
    kindly tell how can we limit our search to a particular node instaed of the whole content
    thanks in advance

    Since it's all text, why not use a real quick Match Pattern (or Regular Expression, but you don't need that much power here), see attached.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ
    Attachments:
    Two-stage match demo.vi ‏8 KB

  • How to access parent, child nodes and attributes in XML?

    EXAMPLE CODING:
    [Embed("assets/Try.xml", mimeType="application/octet-stream")]
    private static consTTest:Class;
    public static function getTestXML() : XML
    var baTest:ByteArrayAsset = ByteArrayAsset( new test() );
    var xmlTest:XML = new XML( baTest.readUTFBytes( baTest.length ) );
    return xmlTest;   
    public function SetTest():void
         var xml:XML = XMLResource.getTestXML();
         var XMLDoc:XMLDocument = parseXML(xml);
         var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
         var resultObj:Object = decoder.decodeXML(XMLDoc);
         trace(resultObj.Roots.Child[0].ChildTitle); //Output: ChildTesting  -> CAN GET IT, NO PROBLEM.
    QUESTIONS:
    (1) How to get the output for
    trace(resultObj.Roots.Child[0].Child1.Inside[0].InsideTitle); //GOT ERROR, THE OUTPUT I NEED IS InsideTesting1.
    (2) How to get the output for
    trace(resultObj.Roots.Child[0].Child1.Inside[0].Tasks.Task[0].TaskTitle); //GOT ERROR, THE OUTPUT I NEED IS TaskTesting1.
    Anyone can help me to solve this problem? Thanks.
    Regards,
    Jessie

    Hi.
    You have error in Try.xml in row 2:
    <Child ... "/>
    Delete '/', its end of this child.
    This is problem...

  • How to disable a particular node in JTree?

    Hi
    I am working with an application where in which I have a tree component and when a select a node and click a disable button , I want to disable the selected node(that is no further selection of that node possible until I enable it). I am using DefaultTreeCellRenderer for rendering nodes. I tried the following.
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer)tree.getCellRenderer();
    JLabel label = (JLabel) renderer.getTreeCellRendererComponent(tree,selectedNode,true,true,false,row,true);
    label.setEnabled(false);
    But it doesn't work.
    Does any one know how to do this?
    Thank you.

    Its not going to work if you implement the TreeCEllRenderer, cos' all it does is paint your tree.
    What u need to implement is the treeSelectionListener interface,
    and override the addSelectedPath(path), addSelectedPath(paths[]) etc.
    You might want to create a list of all the nodes that the user selectes to diable, and then in these methods decide if the node is that then do not allow its selection.

  • How to create a Child node in Tree object

    Hi All,
    I have a thought to create a tree with a child object, that the child can able to create through by right click the parent tree having the options to create or delete the child objects.Please Suggest me if  there is an possible way.
    Thanks
    Gopinath

    Look at sample programm BCALV_TREE_DEMO,
    and especially at the methods ADD_NODE or  DELETE_SUBTREE of class CL_GUI_ALV_TREE.
    For implementing the context menu, consider event ITEM_CONTEXT_MENU_REQUEST.
    Regards,
    Ulrich

  • How to find Last Child (Node) of a parent

    Hi All
    I have following data:
    PARENT CHILD
    1 2
    2 3
    3 4
    4 5
    100 101
    101 102
    200 201
    300 301
    301 302
    302 303
    303 304
    Now I need the output as below:
    Parent Final Child
    1 5
    100 102
    200 201
    300 304
    Which means, for the parent, it should start with immediate child and traverse through all subsequent parent-child relation ship and should find at ending with the last child for that group.
    When the parent child relation is as below: i need to output 1 (first parent in the group) & 5 (last child in the group)
    1 - 2 - 3 - 4 - 5
    Quick solution could be helpful.
    Thanks in advance,
    Ram.

    It seem that you asked for leafs from all roots.
    If so try this
    Processing ...
    with Test_Data as (
      select 1 as parent, 2 as child from dual union all
      select 2, 3 from dual union all
      select 3, 4 from dual union all
      select 4, 5 from dual union all
      select 4, 6 from dual union all
      select 100, 101 from dual union all
      select 101, 102 from dual union all
      select 200, 201 from dual union all
      select 300, 301 from dual union all
      select 301, 302 from dual union all
      select 302, 303 from dual union all
      select 303, 304 from dual
    Levels as (
      select child, level as lvl, connect_by_root parent as root
      from test_data td
      start with parent not in (select child from Test_Data)
      connect by parent = prior child
    ), paths as (
         select child,root,lvl,
              max(lvl) over (partition by root) max_lvl
         from Levels
    select root,child
    from paths
    where lvl= max_lvl
    Query finished, retrieving results...
                     ROOT                                   CHILD                
                                         1                                      5
                                         1                                      6
                                       100                                    102
                                       200                                    201
                                       300                                    304
    5 row(s) retrievedBye Alessandro
    Edited by: Alessandro Rossi on 1-set-2008 12.41
    I've never imagined that a simple copy and past would do that!
    I won't leave it so the new forum supporters ( if any exist ) could see what the cr4p we are using now

  • Help needed with finding node in JTree

    Hi,
    In my application i will be entering some string data in a text box for search criteria.
    When I click on search, I will get data from database which will be shown as a JTree.
    This Jtree will have some nodes in which, node with string entered in the search text box exists.
    I need to focus on this node and I have only a string to find this node.
    How can I do this?How can I find a node in JTree using string value?
    Is there any alternate option by which I can achive my need?
    Please suggest.
    Thanks.

    @OP: please assign your dukes.
    @Andre_Uhres: if you don't get rewarded in the next couple of days, please let me know here to get at least one duke for your effort.
    Bye.

Maybe you are looking for

  • File not opening in original custom size

    How do i configure illustrator to display a file to open at its custom size that it was originally created in. I have a document that was originally create 450 mm x 600 when it opens it is oversize of the viewing default

  • Different Service Desks in different clients in the same Solution Manager?

    Hi Is it possible to place different Service Desks in different clients in the same Solution Manager? Concrete we plan the following  scenario: - Division 1   -- System 1,2,3, etc.   -- Service Desk  in client 100   -- Monitoring for the whole trust

  • Nokia E65 - MMS/Internet Problems

    Hey all. Just having a few problems with my Nokia, recently I have gone with Vodafone from Optus, and having a few troubles sending MMS's and getting on the net. I checked the sticky and searched on google, tried to download the settings etc, but whe

  • Socket in flex

    Hi, We have a c program with tcp server socket running, we want to create a client tcp socket in flex and connect to c program. Can somebody help us with some basic sample codes.? Thanks in advance.

  • Error when trying to purchase songs with iTunes account

    Hi, is anyone able to help with this. I am tryig to purchase some songs with my iTunes account (it is inn credit by about £6) but an error keeps coming up every time i try to purchase a song or if i try to view my account details. It is as if i am pu