JTree adding to expanded nodes

Hey,
I'm writing a program that contains a JTree with two parent nodes and child nodes that are added/removed on demand.
Basically I can't add child nodes while the parent node is expanded. Following the code it actually does add it, just does not update the display.
I've tried validate/repaint/anything I could find that may be of some help with no luck.
Any ideas?
Thanks in advance :)

What do you think about the library I created which
addresses this issue?
Denis Krukovsky
http://dotuseful.sourceforge.net/
I looked at your site and spent 20 minutes trying to figure out why your classes are useful. It's not at all clear why someone should use them. I also looked over your previous posts, but you never seem to explain why someone should use them.

Similar Messages

  • Reload JTree and keep expanded nodes

    Hi all,
    I have spent some time looking around on this, found some useful stuff, but I still cannot seem to get a result.
    Here is my situation:
    I have a JTree for a GUI desktop app. I build the tree from a database file. The user has the ability to refresh the tree to keep it in sync with any database changes. The problem is that when I refresh, all the nodes that were previously expanded are now collapsed again.
    Having looked around, I have seen a lot of JTree.expandRow() answers, but I don't want to use expandRow, as the rows will changes according to any db changes.
    I thought a good solution would be to trap any expand or collapse events and for each either add or remove the TreePath for the relevant node onto a List. When the users refreshes the tree, I thought I could run through the list and expand any TreeNodes I find. I also found someone advocating such an approach in another thread. BUT - it doesn't work for me Here is the code for my refresh. Any help/advice, greatly appreciated.
    Thanks in advance,
    Steve
    private void refreshBrowser(){
            System.out.println("Refresh browser - Started");       
            rootTreeNode.removeAllChildren(); // remove all nodes from root
            loadBrowserData(); // This method loads nodes from a database
             Iterator<TreePath> TPI = objectTreePaths.iterator(); // run throught my saved paths
            while (TPI.hasNext()) {
                TreePath yTreePath = TPI.next();           
                browserTree.expandPath(yTreePath); // Expand each found path
            treeModel.reload(); // model changed - reload it.
            System.out.println("Refresh browser - Complete");       
        }

    Here is my situation:
    I have a JTree for a GUI desktop app. I build the
    tree from a database file. The user has the ability
    to refresh the tree to keep it in sync with any
    database changes. The problem is that when I refresh,
    all the nodes that were previously expanded are now
    collapsed again.
    Having looked around, I have seen a lot of
    JTree.expandRow() answers, but I don't want to use
    expandRow, as the rows will changes according to any
    db changes.you could use:
    JTee.scrollPathToVisible(path);
    Where path is obtained in this way from a DefaultMutableTreeNode (TreeNode):
    TreePath path = new TreePath(((DefaultMutableTreeNode)node).getPath());
    I thought a good solution would be to trap any expand
    or collapse events and for each either add or remove
    the TreePath for the relevant node onto a List. When
    the users refreshes the tree, I thought I could run
    through the list and expand any TreeNodes I find. I
    also found someone advocating such an approach in
    another thread. BUT - it doesn't work for me When you perform a JTree.reload() call, it will collapse each node.
    My advice is to call JTree.reload() and then call JTree.scrollPathToVisible(path) for each TreeNode previously expanded.
    Hope this can help,
    regards

  • Trouble with JTree's and autmoatically expanding nodes

    I am writing an application which uses a JTree as a method of browsing through a certain structure (like a file system). I am having a little trouble though, with a number of small issues, which I am finding hard to get answers through searches (and have spent a fair while searching). In navigating the tree, I want to be able to automatically expand nodes.
    Firstly, I want the Root node to automatically be expanded. I cannot see ways of doing this. I have seen references to EXPANDED being set for the JTree constructor, but I cannot see any reference in the 1.6 API for this.
    Secondly, I want to be able to expand or hide the contents of nodes through other means than clicking on the icon to the left of a non-leaf-node. For example a button that would hide the contents of (i.e. close) the currently selected node. Code such as:
    myNode.setExpanded(true);
    myNode.setExpanded(false);and
    myNode.isExpanded();

    That's the ticket - again something I had seen, but had been using in the wrong way, but your suggestion has helped me get it right. I was trying to expand the path before any more nodes were added to the root node. Then nodes are added, and the application loaded with the root node collapsed. So now I have placed the call at the end of the recursive call to populate the tree.
    Thanks again.

  • Expanding nodes in JTree

    I have an application that uses JTree
    I create the Jtree but I want to expand to see and select a node.
    I have the object of the node and the TreePath but I can't expand the tree using expandPath(), makeVisible(), scrollPathToVisible(path), etc. It seems that JTree doesn't detect the path I use as input.
    But when I use setSelectionPath(path) it is selected (I know because I see information about the node) but it is not displayed nor viewable.
    I only can expand nodes using expandRow(int).
    Does anybody know how expand and select nodes without clicking with mouse?

    expandPath(Treepath treePath) should work. Its possible that your treePath is wrong. How do you get the treePath?

  • Positioning expanded nodes on JTree

    Hey all,
    Does anyone know how to position an expanded node on a JTree to scroll inwards to the right (towards the current expanded level) and move to the top of the Panel it sits in? Kinda like Windows explorer.
    Any help will be greatly appreciated. Thanks in advance,
    zia

    Try to use
    setScrollsOnExpand(boolean�newValue) method of JTree
    regards
    Stas

  • Select Expanded nodes in JTree

    Hi all,
    In the given tree structure, I want to get a node to be selected, once it is expanded.
    + Folder1
    - Folder2
          |
          |__-Folder3
           |
           |__-Folder4
              |
                |__ file1.docCurrently, if I have Folder1 selected and if I expand Folder2, the selection remains at
    Folder1 itself. I need to change the selection to Folder2.
    Also, I need to get the path of the expanded node . ie; when Folder4 is expanded, I need to
    get Folder4 selected and path has to be obtained as \Folder2\Folder3\Folder4.
    I found this link helpful-- http://forums.sun.com/thread.jspa?messageID=3616726, but there
    also, the path is obtained based on selection and not based on expansion.
    Please help with a solution
    Regards,
    Anees

    AneesAhamed wrote:
    Hi all,
    In the given tree structure, I want to get a node to be selected, once it is expanded.
    + Folder1
    - Folder2
    |
    |__-Folder3
           |
           |__-Folder4
              |
                |__ file1.docCurrently, if I have Folder1 selected and if I expand Folder2, the selection remains at
    Folder1 itself. I need to change the selection to Folder2.
    Also, I need to get the path of the expanded node . ie; when Folder4 is expanded, I need to
    get Folder4 selected and path has to be obtained as \Folder2\Folder3\Folder4.
    I found this link helpful-- http://forums.sun.com/thread.jspa?messageID=3616726, but there
    also, the path is obtained based on selection and not based on expansion.
    Please help with a solution
    Regards,
    AneesTo expand any node you need to "know" it either due to a user's mouse click or inside the code that expands it directly, something like :
    - by mouse click :
    myJTree.addMouseListener(new MouseAdapter()
         public void mouseClicked(MouseEvent e)
              TreePath treePath = getPathForLocation(e.getX(), e.getY());
    });- direct code :
    public void treeWillExpand(TreeExpansionEvent e)
         TreePath treePath = e.getPath();
    }Then you can get the corresponding node from the TreePath :
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent();But for a selection this should be enough :
    myJTree.setSelectionPath(treePath);
    myJTree.scrollPathToVisible(treePath);Regards,
    Lara.

  • Expanded node and children are seen only after second expansion

    Hi,
    I am using a simple JTree control. I am populating children of nodes dynamically when the node is expanded. For this, I first add a "dummy" item for each node under the root, so that the "+" sign appears next to the node. When a node is expanded, I delete the "dummy" node and add children to it. However, the first time I expand the node, the node actually doesn't expand, though treeExpanded() gets called and all children are added correctly (I verified by debugging). When I expand the tree the second time, I can see the expanded node.
    I am using TreeModel's removeNodeFromParent(childNode) and insertNodeInto(childNode, parentNode, childIndex) method to remove and add children respectively.I believe we don't have to explicitly call TreeModel's nodeChanged(), nodesWereInserted() etc?
    Could you please let me know if I am missing something fundamental here?
    Thanks in advance,
    Praneeth

    Hi db,
    I didn't realize that there was a response to my earlier thread. I added the thread to my watchlist. I was under the impression that I would be notified via email in case of a reply to the thread. However, I didn't receive any. Anyway, I did reply to that response there now.

  • Adding additional j2ee node

    Hello,
    we are running BI 7 - abap+java stacks with 16 GB ram (recently added)
    i would like to know what is the thumb rule for adding additional j2ee node?
    when is it neccassary to add additional j2ee node?
    Regards,
    Moshe

    Hi,
    The JLaunch starts a Java program. It loads the JVM into its own address space and then represents the required cluster element. The program can receive notification from the JControl process via named pipes to stop the cluster element, and terminates, if the JControl stops running (fork emulation under Windows).
    So Jlaunch consuming high CPU time means that server, dispatcher or bootstrap process consume it. If there are not enough system or application threads avaliable means that the engine must buffering requests for web application or system processes. Things to check in this case are:
    SAP NOTE 1016241 - J2EE Engine hangs because of unsufficient system threads
    SAP note: 716604  and upgrade JDK.
    SAP note: 723909 -> set correct VM parameters
    and if issue persists, then you will need to analyse the application causing teh leak...
    SAP note: 1259465: Memory analyser.
    Regards,
    Hemanth

  • Help in getting current expanded node in Tree UI

    HI,
    I have a requirement to build a tree dynamically. On expanding each node I need to create sub nodes inside that. But it is always creating inside the node where the lead selection is and not inside the current expanded node. Even though I have used getTreeSelection () to get the current element.
    <b>Detailed description about the application.,</b>
    I have created a context with the following structure,
    TreeNode (0..n)
    |
    |--> ChildNode (recursive SiteTree)
    |--> Name (string)
    I have created a Tree UI Element in the view and inserted a node type 'TreeNodeType'.
    I have set the properties of the inserted node type as given bellow,
    Value Attribute in TreeNode -> Name I have assigned to 'Text' property of 'TreeNodeType'.
    Initially I have created four nodes in the init() method ., using the following code :
    for(int i=0;i<3;i++)
    IPrivateTestTreeView.ITreeNodeNode treenode=wdContext.nodeTreeNode();
    IPrivateTestTreeView.ITreeNodeElement treeelement=wdContext.createTreeNodeElement();
    treeelement.setName("Testroot:"+i);
    treenode.addElement(treeelement);
    Now I need to create sub-nodes for this dynamically.,
    I have created an action and called it in 'onLoadChildren' event of 'TreeNodeType' with the following code:
    public void OnCurrentSelection()
    IPrivateTestTreeView.ITreeNodeElement el = wdContext.nodeTreeNode().getTreeSelection();
    wdComponentAPI.getMessageManager().reportSuccess(el.getName());
    <b>
    Where this returns me only the name of LeadSelection node and not the  node which i try to expand.  </b>
    Is there anyway I can get the currently expanded node., Kindly help me out in this.
    Points will be rewarded for helpful answers. Thanks in advance.
    Regards,
    Nirmal

    HI Ayyapparaj ,
    <b>First I would like to thank you for your reply.</b>
    So it means that we cannot identify the currently expanded node in tree UI element and It will always be the lead selection node we will be able to get rite?
    Can we make the current lead selection to currently expanded node 'By Default'?
    Coming back to your solution.,
    I created a context element 'isExpanded' of type boolean inside the TreeNode.
    You said that there will be a call made to 'getter and setter' methods while we expand the node and we can set the lead selection to that element from there.
    Could you please give me some more details of how to achieve it.
    Thanks in advance.
    Regards,
    Nirmal G

  • Af:treeTable component: API to return list of expanded nodes?

    Hi,
    In my UI design, I am using a tree table (af:treeTable component). Does the framework support API to return (at any given time) a list of all expanded nodes?
    I realize that I can build logic to 1. return the currently selected node, then 2. query up all of the child nodes of this selected node. However, I'm wondering if, say at a particular instant, multiple nodes have been expanded, and I need a list of all of these nodes for every level in the tree table?
    Thanks in advance,
    Monica

    Hi John,
    I am using 11g. From the javadoc, I see that getDisclosedRowKeys() returns "set of disclosed rows for [tree-table] component" and "each entry in the set is a rowKey."
    What exactly is the definition of a "disclosed row"? I'm guessing this means any & all rows shown from UI, which would return all rows (including parent nodes of newly expanded nodes)?
    Is there a way to return all child nodes (newly displayed rows) of expanded nodes? To clarify, I'm trying to gather rows level by level. If a node has been expanded at level n, I would like to get a new list of nodes at level (n+1).
    Thanks,
    Monica

  • Only 1 expanded node each time - MenuTree

    I use a <af:menuTree> component with 2 level nodes.
    How can I put only one expanded node each time (of first level). By other words, when I expand 1 node (first level) the others expanded nodes must not be expanded automatically ?
    Thanks,
    Sérgio Morais

    Sergio,
    managed bean:
    package adf.test;
    import java.util.Set;
    import oracle.adf.view.faces.component.core.nav.CoreMenuTree;
    import oracle.adf.view.faces.event.DisclosureEvent;
    import oracle.adf.view.faces.model.PathSet;
    public class MenuTreeBean {
    public MenuTreeBean() {
    public void onDisclosure(DisclosureEvent disclosureEvent) {
    CoreMenuTree cmt = (CoreMenuTree) disclosureEvent.getSource();
    Object rwKey = cmt.getRowKey();
    //quick and dirty check for tree level
    if (rwKey.toString().indexOf(",") == -1){
    PathSet ps = cmt.getTreeState();
    Set ks = ps.getKeySet();
    ks.clear();
    ks.add(rwKey);
    JSF tree
    <af:menuBar id="mbar">
    <af:menuTree value="#{bindings.DepartmentsView1.treeModel}" var="node"
    disclosureListener="#{menuTreeBean.onDisclosure}"
    id="menutree">
    <f:facet name="nodeStamp">
    <af:outputText value="#{node}" id="nodeId"/>
    </f:facet>
    </af:menuTree>
    </af:menuBar>
    Frank

  • How to get only expanded node after open & close in CL_GUI_ALV_TREE?

    Hi,
    I have a tree structure using CL_GUI_ALV_TREE.
    I would like to capture only the expanded nodes AFTER open and close operation.
    If the user opens all the nodes and then closes them, I get all the nodes when using GET_EXPANDED_NODES.
    I want to get only the expanded nodes that the user currently sees on the screen (so in open and close you will not get it as open).
    whatever I tried doesn't work.
    Do you have any idea how to do it?
    Thanks,
    Itay

    this methods calls method of attribute MR_COLUMN_TREE without setting the parameter NO_HIDDEN_NODES to 'X'
    that's why you get every node that is "open" even if not "visible"
    as this attribute MR_COLUMN_TREE is protected, you cannot access it...
    you should consider using an object of class CL_GUI_COLUMN_TREE directly in place of CL_GUI_ALV_TREE so that you can call the method with this parameter set...
    you will have far more to do by hand but you will get more flexibility...

  • ALV Tree, Expanded node do not show data in certain column

    Hi all,
    I need your help regard to below problem.
    I have an ALV grid in which one of the columns has F4 (search help). If search help is called by pressing a F4 button a dialog box will be shown with ALV tree on it.
    The ALV Tree has 2 columns which are: hierarchy column and one other column called WBS column. At the first show, all expanded node show data contained in WBS column, but if I click to expand a collapsed node, data is not shown in WBS column for the new expanded rows, only shows data in hierarchy column. How to show data in WBS column for the new expanded rows..?
    Basically if at the first show I expand all node, data in WBS column are shown for all rows. It seems that the Expand Node event doesn't update all column data to be shown.
    Please share if anyone of you has faced this kind of problem. Thank you.
    Regards,
    Ramses Hutahaean
    Edited by: Ramses Hutahaean on Feb 29, 2012 1:38 PM

    Hi Fenja,
    as the click-events only raise the node_key (at least I couldn't detect another information), I assume the only way is maintaining an internal helper table by yourself which you build up in parallel when creating the tree and its nodes.
    The (hashed) table might contain 2 columns:
    1. node_key (as table key)
    2. reference to an object
    When a click-event is raised, you look up the corresponding object reference in your table.
    Regards,
    Ulrich

  • Manual of adding the new node on RAC with ASM

    Hello everbody
    Someone have the manual of the adding a new node on RAC with ASM for Solaris ?
    regards
    Spaulonci

    Go to http://www.oracle.com/technology/documentation/index.html, select your unknown database version and search for a manual named 'Oracle Clusterware and Oracle Real Application Clusters Administration and Deployment Guide'.
    Werner

  • Expandable nodes- anyone here really use them?

    I recently discovered the "expandable node" in LV ( I know, I'm late to the game here but as an old LV hand I often discover "new" features a bit late).  Does any non-beginner actually use these?  I think of these the same way I think of the big terminal icons- a waste of BD space.  Plus it sort of makes your BD look like the "Playskool" version of LabVIEW....

    Ravens, you know I just posted this question to show off my "Elmo" icon

Maybe you are looking for

  • "WITH"  causes key cannot be null

    Hi Is the problem using "WITH" in sql statement with bind variables solved.i am using ODP.NET 9.2.0.4.01 version.Are there any patches to solve the above problem. regards srinivas

  • Sony 3D BluRay Player

    I just bought this 3-D player and when I load up Madagascar3 in3-D (that I bought at Best Buy) it shows a screen that I must have a compatible 3-D player to see the movie. I can see the 2D movie. Spending 30 bucks for a movie that I can't see on this

  • RMAN unable to exit

    We are working on AIX 6.1 with Oracle 11gR2, we are facing any issue during the restore operation and the RMAN is not existing after restore channel ORA_SBT_TAPE_2: reading from backup piece sun2gm3b_1_1 channel ORA_SBT_TAPE_1: piece handle=svn2g23b_

  • Need Balance Query

    create table users ([uid] INT PRIMARY KEY IDENTITY(1,1), name nvarchar(100)) create table balance(bid INT IDENTITY(1,1) PRIMARY KEY, [uid] INT, dr FLOAT, cr FLOAT, FOREIGN KEY ([uid]) REFERENCES users([uid])) GO insert users ([Name]) values ('Haider'

  • Brother HL-1240 included Intel gimp-print drivers and Acrobat 8.1

    For some reason it is hard to get Acrobat Reader to print at 100% with Brother's HL-1240 gimp-print drivers using Acrobat Reader 8.1 on a Mac Pro running 10.4.9. I have no trouble with it appearing 100% on my iMac Intel Core 2 Duo and an Epson R220,