JTree get selected node/object values

I wan to get all the selected nodes/objects values that I added to the JTree. How can I do this?
Thanks.

TreePath[] paths = tree.getSelectedPath();
for(int i = 0; i < paths.length; i++){
TreeNode node = (TreeNode)paths.getLastPathComponent();
Object mySelectedObject = node.getUserObject();
}Some minor Errors
We have to use array paths[i] instead of paths
The correct code as used by me is
        javax.swing.tree.TreePath[] paths = jTree1.getSelectionModel().getSelectionPaths();
        for(int i = 0; i < paths.length; i++){
            javax.swing.tree.TreeNode node = (javax.swing.tree.TreeNode)paths.getLastPathComponent();
System.out.println(((javax.swing.tree.DefaultMutableTreeNode)node).getUserObject());
CSJakharia

Similar Messages

  • HOw to get parent node name value through its child node?

    Hi,
    Experts,
    I am able to get child node name values but according to attribute name value i want to  get its parent name value how to achieve that. For that i have used If_Ixml_element->Get_parent. Please pass some idea on it.
    Thanks in advance,
    Shabeer ahmed.

    Hello Shabeer
    I think the coding should be straightforward:
    DATA: lo_element   TYPE REF TO if_ixml_element,
              lo_child        TYPE REF TO if_ixml_node,
              lo_parent      TYPE REF TO if_ixml_node.
    " NOTE: LO_ELEMENT holds your child node
      lo_child ?= lo_element.
      lo_parent = lo_child->get_parent( ).
    Regards
      Uwe

  • How to get selected Row/Cell value in i5Grid

    Hi Friends,
    Can anyone help to how to find the selected Row/Cell value of a i5Grid object. I am able to register the event handlers which are getting invoked on row/cell selection. But I want to know how can I get the value of selected Cell/Row. I would like to add selected Items from one i5Grid to another one.
    So want to know how can I get and set the value of i5Grid object.
    MII version 14.0 SP4 Patch
    Thank in advance
    Shaji Chandran

    Hi Shaji,
    Here is my code.
    <!DOCTYPE HTML>
    <HTML>
    <HEAD>
        <TITLE>Your Title Here</TITLE>
        <META http-equiv="X-UA-Compatible" content="IE=edge">
        <META http-equiv='cache-control' content='no-cache'>
        <META http-equiv='expires' content='0'>
        <META http-equiv='pragma' content='no-cache'>
        <SCRIPT type="text/javascript" src="/XMII/JavaScript/bootstrap.js" data-libs="i5Chart,i5Grid,i5SPCChart"></SCRIPT>
        <SCRIPT>
            var Grid = new com.sap.xmii.grid.init.i5Grid("STC/C5167365/i5Grid_TagQuery", "STC/C5167365/TagQuery");
            Grid.setGridWidth("640px");
            Grid.setGridHeight("400px");
            Grid.draw("div1");
        function setCellValue()
        Grid.getGridObject().setCellValue(1,1,"Set");
        function setCellValueAgain()
        Grid.getGridObject().setCellValue(1,1,"Changed Again");
        </SCRIPT>
    </HEAD>
    <BODY>
        <DIV id="div1"></DIV>
        <INPUT type="Button" value="setCellValue" onClick="setCellValue()"/>
        <INPUT type="Button" value="setCellValueAgain" onClick="setCellValueAgain()"/>
    </BODY>
    </HTML>
    Regards,
    Sriram

  • JTree and selected node question

    Hello
    Is it possible to convert the selected node to an int?
    I guess I'm looking for something llike this.
    int nodeNumber = node.getSelectedIndex();
    There is nothing like that in the API, and it would help greatly if I could find a way do this.
    Thanks
    Have a good holiday
    Jim

    From the API for JTree
    public int getMinSelectionRow()
    Gets the first selected row.
    Returns:
    an integer designating the first selected row, where 0 is the first row in the display
    But I think this is based on how many rows are displayed at the present time and might change if the tree is opened above it.

  • Get selected art object

    I am trying to get the user selected art object properties, I tried written the code below and realised this get all the objects in the layer and store all of them in the AIArtHandle instead of what I selected. I only want to print out the one user selected, how??? any help???
    AIMatchingArtSuite *aiArtMatch;
    sBasic->AcquireSuite( kAIMatchingArtSuite, kAIMatchingArtSuiteVersion, (const void**)&aiArtMatch );
    AIArtHandle **artStore = NULL;
    long artCount = 0;
    aiArtMatch->GetSelectedArt(&artStore, &artCount);
    AIArtHandle my_artHandle = (*artStore)[0];

    I believe the problem you're having is that selection 'climbs upwards'. That is, if you select some art you also select it's parent, and its parent's parent, etc.
    So even if you just select a single path, you're also selecting the group that represents the layer. As such, you might be able to just ask the art if it's a layer group using AIArtSuite::IsArtLayerGroup() and ignore it if it is. I believe the rest will be an accurate depiction of what's selected, be it on art or many.
    Oh, and if the art you've selected is a compound path, that call will also include all the sub-component paths. If you don't want them, you can also ask each art in your set if it's part of a compound path by using AIArtSuite::GetArtUserAttr() with kArtPartOfCompound; I believe you can ignore anything that has that, though I'm not sure how it responds when you pass it the container kCompoundPathArt.
    Hope that helps!

  • Get selected node of an adf tree in backing class

    hi,
    i am deploying an adf web application, i use jdeveloper 11g and a weblogic webserver.
    i have a bean family this bean contains a list of families and a parrentfamily object, so it is a rekursive relationship.
    i use the adf tree component to show all the families starting with the root family. works fine. only had to create a data controle of the bean and with dragndrop i create the adf tree.
    now i want to create a subfamily of any family shown in the tree, so i need the selected tree node in my backing bean (in a methode which is the action of my buttono) of the adf page.
    but iam unable to get the data.
    so my question i searched many times for:
    What is the best and easiest way to get the selection of an adf tree in the backing bean of the page?

    Hi,
    here's how you get the object itself, assuming your model is POJO based. Assuming "tree" is a variable pointing to a RichTree instance
    CollectionModel treeModel = (CollectionModel) tree.getValue();
    JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) treeModel.getWrappedData();
    RowKeySet rks = tree.getSelectedRowKeys();
    if(!rks.isEmpty()){
      List firstSet = (List)rks.iterator().next();
    JUCtrlHierNodeBinding node = treeBinding.findNodeByKeyPath(firstSet);
      DCDataRow rw = (DCDataRow) node.getRow();
      //get the object
    Object entity = rw.getDataProvider();       
    }                         Frank

  • Getting selected LOV's values

    Many posts are related to LOVs.
    Following steps I used :
    1.     Using the responsibility AK Developer, I created the region XXCU_MOUVEMENT_TOP, and in Jdev its CO MouvementCreerCO
    2.     Using the responsibility AK Developer, I created the LOV region XXCU_NUMERO_FACTURE_AR_LOV
    3.     the XXCU_NUMERO_FACTURE_AR_LOV is inserted into XXCU_MOUVEMENT_TOP
    4.     In Jdev created a ViewObject XxCuFactureARVO, with 6 attributes and its CO FactureARLovCO
    The XXCU_NUMERO_FACTURE_AR_LOV works fine, it popup a window search and I can do search and displays all attributes (6 values).
    I want to get all them to dispay them in attributes of XXCU_MOUVEMENT_TOP. The problem is that I can't get them
    In processRequest and processRequestof FactureARLovCO
    (String)pageContext.getParameter("Solde")
    (String)pageContext.getParameter("CodeBvrb")
    (String)pageContext.getParameter("XxNomuo")
    Are null.
    How can I get the selected values of XXCU_NUMERO_FACTURE_AR_LOV from XXCU_MOUVEMENT_TOP, I'll appreciate your help

    Under the Lov, create lovmappings for each of the attributes that you want to grab back from the lov page.
    - Right click on the lov -> Select New -> lovmap.
    - In the lov map, specify the LOV Region Item (The LOV Region Item who's value you want in the base page) and the Return Item (The base page region item, where you'll like to have the value back into).
    HTH.

  • HOw to get selection node h2 tag on http agility pack

    <div id="content">
    <div class="sense-block" id="1-1>
    <h2>
    <span class="hw">appear</span>
    <span class="posgram">
    <span class="pos" title="A word that describes an action, condition or experience.">verb</span>
    </span>
    <span class="guideword" title="Guide word: helps you find the right meaning when a word has more than one meaning">
    (BE PRESENT)
    </span>
    </h2>
    <div class="sense-body">
    <span class="def-block">
    <span class"def-body">
    <span class"examp"></span>
    <span class"examp"></span>
    </span>
    </span>
    <span class="def-block>
    <span class="def-body">
    <span class"examp"></span>
    <span class"examp"></span>
    </span>
    </span>
    </div>
    </div>
    <div class="sense-block" id="1-2>
    <h2></h2>
    <div class="sense-body">
    <span class="def-block"></span>
    <span class="def-block></span>
    </div>
    </div>
    </div>
    var newsListNodehtml = htmlDoc.GetElementbyId("1-1");
    if(newsListNodehtml!=null)
    var senseblock = newsListNodehtml.Descendants("span").Where(x => x.GetAttributeValue("class", "") == "def-block");
    if(senseblock!=null)
    foreach(var node in senseblock)
    Dictionaries = new Models.EnglishDictionary();
    var title = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "def");
    var examp = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "def-body");
    //Dictionaries.Symbol = "/Photos/glasses-50.png";
    if (title != null)
    Dictionaries.Description = title.InnerText.Trim();
    if (examp != null)
    Dictionaries.Examp = examp.InnerText.Trim();
    var hw = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "hw");
    var prsgram = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "posgram");
    var word = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "guideword");
    if (hw != null)
    Dictionaries.Word = hw.InnerText.Trim();
    if (word != null)
    Dictionaries.GuideWord = word.InnerText.Trim();
    if (prsgram != null)
    Dictionaries.Grammar = prsgram.InnerText.Trim();
    //Dictionaries.Phrase=pharsel.InnerText;
    arrays.Add(Dictionaries);
    <div id="x_x_1-1>">
    var senseblock = newsListNodehtml.Descendants("span").Where(x => x.GetAttributeValue("class", "") == "def-block");
    So, senseblock will not be have <h2> tag. Of couse that results is null to (foreach will be play two time and getting def-block two times"
     But If I changed It(senseblock ) to 
              var newsListNodehtml = htmlDoc.GetElementbyId("content"); // content is contain all tag
                if(newsListNodehtml!=null)
                    var senseblock = newsListNodehtml.Descendants("span").Where(x => x.GetAttributeValue("class", "") == "sense-block");
    Then  foreach that just play the def-block once time.
    Note: I'm still want get all of h2 tag and def-block(two time because of having 2 div def-block tag)in id 1-1. How???

    Thanks, I figured out this my ways to solve it.
    I want ask you: How to return Lis<> (async). 
    Ex:
    public async void loaddata(string id)
    var httpClient = new HttpClient();
    var srtHtml = await httpClient.GetStringAsync("http://dictionary.cambridge.org/dictionary/british/appeal");
    var htmlDoc = new HtmlDocument();
    htmlDoc.LoadHtml(srtHtml);
    List<Models.EnglishDictionary> arrays = new List<Models.EnglishDictionary>();
    var newsListNodehtml = htmlDoc.GetElementbyId("entryContent");
    if (newsListNodehtml != null)
    var senseblock = newsListNodehtml.Descendants("div").Where(x => x.GetAttributeValue("id", "") == id);
    if (senseblock != null)
    foreach (var node in senseblock)
    Dictionaries = new Models.EnglishDictionary();
    var def = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "def");
    var examp = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "def-body");
    //Dictionaries.Symbol = "/Photos/glasses-50.png";
    if (def != null)
    Dictionaries.Description = def.InnerText.Trim();
    if (examp != null)
    Dictionaries.Examp = examp.InnerText.Trim();
    var hw = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "hw");
    var prsgram = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "posgram");
    var word = node.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "guideword");
    if (hw != null)
    Dictionaries.Word = hw.InnerText.Trim();
    if (word != null)
    Dictionaries.GuideWord = word.InnerText.Trim();
    if (prsgram != null)
    Dictionaries.Grammar = prsgram.InnerText.Trim();
    arrays.Add(Dictionaries);
    else
    // error = "No data";
    Listview.itemsource=arrays;
    I want on ousite it will called back into "itemsource" of lisview.
    Ex:Listview.itemsource=loaddata("1-1");
    How???

  • Get current Tree Select Node

    Hi,ALL
    I want to return JTree selection.
    As you know If use JTree object, we can use
    getSelectionPaths(), and use Treepah object method
    getLastPathComponent to get selected node.
    What I want to do is.
    My JTree Object model is DefaultMutableTreeNode
    i want to use DefaultMutableTreeNode to access selected Node.
    Can I do like this?
    If I can, how to do it?
    Thanks in advanced

    Hi,
    if you following that pdf ,
    i think your not implemented the below code in DomodifyView method
    if (firstTime) {
          IWDTreeNodeType treeNode = (IWDTreeNodeType) view.getElement("TheNode");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "selectedElement".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onAction event. Parameter "selectedElement" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onAction. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnAction().addSourceMapping("path", "selectedElement");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "element".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onLoadChildren event. Parameter "element" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onLoadChildren. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnLoadChildren().addSourceMapping("path", "element");
    please cross check once.
    Thanks,
    Ramesh

  • Using OVS (Object value selector) inside a tabe.

    I am new to the WebDynpro Java development. I am developing a simple UI ,where I have to put inputfield in table row and apply OVS to that inputField. I have already done that , but the problem is when selecting the inputField the value hep button is showing and , when clicking on the value help button nothing happens.Can any body suggest me , how to use OVS inside a table row.
    Thanks,
    Srikanta

    Hi Srikanta,
    you can use object value help selector in table by creating a singleton node attribute by this you will make sure that one row's value is not affected by other row's value selection for object value help please refer to this wiki article [Value Help - Object Value Selector|http://wiki.sdn.sap.com/wiki/display/WDJava/ValueHelp-ObjectValue+Selector]. Please let us know if you need any help.
    Regards
    Jeetendra

  • How to get the selected node value of a tree which is build on java code

    Hi Experts,
    How can i get the selected node value if I build the tree programatically.
    I am using the following code in selectionListener but it is throwing error.
    RichTreeTable treeTable = (RichTreeTable)getQaReasontreeTable();
    CollectionModel _tableModel =
    (CollectionModel)treeTable.getValue();
    RowKeySet _selectedRowData = treeTable.getSelectedRowKeys();
    Iterator rksIterator = _selectedRowData.iterator();
    String selectedQaCode ="";
    while (rksIterator.hasNext()) {
    List key = (List)rksIterator.next();
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    JUCtrlHierNodeBinding nodeBinding =
    treeTableBinding.findNodeByKeyPath(key);
    String nodeStuctureDefname =
    nodeBinding.getHierTypeBinding().getStructureDefName();
    selectedQaCode = selectedQaCode + nodeBinding.getAttribute(0);
    where I am using following link to create a tree with java code.
    http://one-size-doesnt-fit-all.blogspot.com/2007/05/back-to-programming-programmatic-adf.html
    Please help me in resolving this issue.
    Regards
    Gayaz

    Hi,
    you should also move
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    out of the while loop as this is not necessary to be repeated for each key in the set
    Frank

  • How could i get the selected node in the JTree

    getLastSelectedPathComponent() �returns the parent node of currenr selected, so how could I get the selected node itself in the JTree
    I will appretiate for any help!

    i think you can get by....
    TreePath treePath = tree.getSelectionPath();
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();

  • JTree: How to get the currently selected node

    How do I get the currently selected node in JTree?
    getLastSelectedPathComponent() this method always return the last selected node and not the current one.
    Thanks in advance
    Sachin

    Use
    TreePath selectedPath = tree.getSelectionPath()If your tree allows multiple selections, use
    TreePath [] selectedPaths = tree.getSelectionPaths() this will return an array of all selected tree paths.
    Once you get the tree path, call the treePath.getLastPathComponent(). this should tell you the currently selected node.
    Hope this helps
    Sai Pullabhotla

  • Jtree Select node and change leafs icon problem

    Hi All,
    i create a tree and implement a TreeSelectionListener:
    my mission is whenever i select a node i need to change the icon of this node (for now.later i will have to find if it have childrens).
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import java.util.Vector;
    import javax.swing.ImageIcon;
    import javax.swing.JTree;
    import javax.swing.event.TreeExpansionEvent;
    import javax.swing.event.TreeExpansionListener;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreeNode;
    import javax.swing.tree.TreePath;
    public class TreeView{
         DefaultMutableTreeNode top;
         JTree tree ;
         Color frameColor;
         public static ImageIcon NoTSelIcon;
         public static ImageIcon SelIcon;
        public static String[] name= new String[8];
         public TreeView(Color BackColor) {
              // TODO Auto-generated constructor stub
            top =  new DefaultMutableTreeNode("Diagnostics");
            this.frameColor=BackColor;
             SelIcon = createImageIcon("../Resource/Images/Select.gif");
             if (SelIcon == null)
                 System.err.println("Tutorial icon missing; using default.");
             NoTSelIcon = createImageIcon("../Resource/Images/NotSelc.gif");
               if (NoTSelIcon == null)
                 System.err.println("Tutorial icon missing; using default.");
         public Component createTreeComponents(){
                //Create the nodes.
                 createNodes(top);
            //Create a tree that allows one selection at a time.
            tree = new JTree(top);
            //TREE LISTENERS
            //Treeselction listener
            Handler hObject = new Handler();
            tree.addTreeSelectionListener(hObject);
           //Tree expand/collapse listener
            HandlerExpansionListener hObjectExpan = new HandlerExpansionListener();
            tree.addTreeExpansionListener(hObjectExpan);
    //       tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
            //set tree background
            tree.setBackground(frameColor);
             tree.setCellRenderer(new OverrideTreeCellRenderer(frameColor,SelIcon,NoTSelIcon));
            return tree;
          private void createNodes(DefaultMutableTreeNode top) {
                 DefaultMutableTreeNode category = null;
                 DefaultMutableTreeNode SubCategory = null;
                 DefaultMutableTreeNode SubCategoryBasee = null;
                 DefaultMutableTreeNode SubSubCategoryBasee = null;
                 category = new DefaultMutableTreeNode("Dfe");
                 top.add(category);
                 //Sub test visible
                 SubCategory = new DefaultMutableTreeNode("Test Visible");
                 category.add(SubCategory);
                 SubCategory.add(new DefaultMutableTreeNode("Son 1"));
                 SubCategory.add(new DefaultMutableTreeNode("Son 2"));
                 SubSubCategoryBasee = new DefaultMutableTreeNode("Test Base");
                 SubSubCategoryBasee.add(new DefaultMutableTreeNode("Grandson 1"));
                 SubSubCategoryBasee.add(new DefaultMutableTreeNode("Grandson 2"));
                 SubCategory.add(SubSubCategoryBasee);
          class Handler implements TreeSelectionListener {
                   public void valueChanged(TreeSelectionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeSelect event ");
                        TreePath trph;
                        trph=arg0.getNewLeadSelectionPath();
                        int count=trph.getPathCount();
                        DefaultMutableTreeNode Selnode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                        String Name = (String)Selnode.getUserObject();
                        setSelected(Selnode,true);
                        int number_ofnodes=getNodeCountBelow((TreeModel)tree.getModel() , Selnode, false);
                        System.out.println("The Number of nodes under "+Name+"="+number_ofnodes);
                        tree.setCellRenderer(new IconRenderer(SelIcon,NoTSelIcon,frameColor));
          class HandlerExpansionListener implements TreeExpansionListener {
                   public void valueChanged(TreeSelectionEvent arg0) {
                        // TODO Auto-generated method stub
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode)  tree.getLastSelectedPathComponent();
                        if (node == null) return;
                      }     // The inner class
                   public void treeCollapsed(TreeExpansionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeCollapsed event ");
                   public void treeExpanded(TreeExpansionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeExpanded event ");
          /** Returns an ImageIcon, or null if the path was invalid. */
             protected static ImageIcon createImageIcon(String path) {
                  //ImageIcon imcon= new ImageIcon(path);
                  //return imcon;
                 java.net.URL imgURL = TreeView.class.getResource(path);
                 if (imgURL != null) {
                     return new ImageIcon(imgURL);
                 } else {
                     System.err.println("Couldn't find file: " + path);
                     return null;
             DefaultMutableTreeNode newnode;
             public void setSelected(DefaultMutableTreeNode Selnode ,boolean isSelected)
                    Enumeration Enchilds=Selnode.children();//ENUMRATE ALL CHILDS FOR THIS NODE
                 if (Enchilds != null)
                      while (Enchilds.hasMoreElements())
                           newnode=(DefaultMutableTreeNode)Enchilds.nextElement();
                           String NameSel = (String)newnode.getUserObject();
                           setSelected(newnode,isSelected);
             //GETTING THE TREE DEPTH
             public int getNodeCountBelow(TreeModel model, Object node, boolean includeInitialNode)
                 int n = includeInitialNode ? 1 : 0;
                 for (int i = 0; i < model.getChildCount(node); i ++)
                     n += getNodeCountBelow(model, model.getChild(node, i), true);
                 return n;
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import javax.swing.Icon;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    public class IconRenderer extends DefaultTreeCellRenderer {
         private static final long serialVersionUID = 1L;
         Icon SelectedIcon;
         Icon NotSelectedIcon;
         Color BackgroundColor;
         boolean Selected=false;
         boolean Leaf=false;
         boolean IsItaChild=false;
         DefaultMutableTreeNode SelctedNode=null;
        public IconRenderer(Icon SelIcon,Icon NoTSelIcon,Color Bacground) {
             SelectedIcon = SelIcon;
             NotSelectedIcon = NoTSelIcon;
             BackgroundColor=Bacground;
             setBackgroundNonSelectionColor(BackgroundColor);
        public Component getTreeCellRendererComponent(JTree tree,Object value,boolean sel,boolean expanded,
                                                        boolean leaf,int row,boolean hasFocus)
             super.getTreeCellRendererComponent(tree, value, sel,expanded, leaf, row,hasFocus);
             Selected=sel;
             Leaf=leaf;
             DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
             String s2 = (String)node.getUserObject();
       return this;
    }my problem is :
    when i select a node the the method "getTreeCellRendererComponent"
    start to run on the entire tree from buttom to top and than from top to buttom.
    for me it waste of time because if has say 100 nodes it wont botthers me.
    but i have 20000 nodes and more its take a time.
    and for all this nodes i have to make compares.
    is there a way to force the DefaultTreeCellRenderer to not run the entire tree???
    Thanks

    You need to make sure that your TreeModel interprets your group nodes to be non-leaf nodes (one of the methods in the TreeModel interface is called isLeaf). If you are using a DefaultTreeModel with DefaultMutableTreeNode objects, you can use the askAllowsChildren property of DefaultTreeModel and the allowsChildren property of DefaultMutableTreeNode to control this. See the API for more details:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultTreeModel.html
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultMutableTreeNode.html

  • JTree select Node

    Is there any method available to select a node by its path in JTree. I have to pass the argument as string type and see the node gets selected. Help !!!!

    well, if you have the node and are using DefaultTreeModel, you can call: getPathToRoot(TreeNode)
    Not sure how to find the node from the value except to just loop thru the entire tree... or maintain a separate table of value/node objects.

Maybe you are looking for