JTree - multiple selection doesn't highlight tree nodes

I have a JTree which was working great with single selection of objects within it. Now i'm expanding this to work with multiple selected objects at the same time, but the objects are not visibly highlighted in the tree.
I switched to using DISCONTIGUOUS_TREE_SELECTION, and using setSelectionPaths(TreePath[]) instead of setSelectionPath(TreePath). This works fine, except that the newly selected paths don't visually highlight any more (worked fine with single selection).
I had thought that the RowMapper was the culprit, but the default VariableHeightLayoutCache seems to be in place and ok. What should i be checking to get this to work right?
Thanks.

/me beats forehead against the desk..
TreePath selectionPath = new TreePath( entityNode.getPath() );
NOT just
TreePath selectionPath = new TreePath( entityNode );

Similar Messages

  • Highlight tree node

    A quick problem for you experts. I am trying to get a node in a JTree to be highlighted with the 'blue' background as if someone has selected it with a mouse click. Unfortunately, setSelectionPath(TreePath path) is not doing this for me.
    I am using a custom TreeCellRenderer which extends the DefaultTreeCellRenderer. Would anyone know what exactly I need to do in my custom renderer to highlight a node?
    thanks.

    Good time for asking your question 'cause I just had a similar problem and finally figured out how to fix it.
    First, the DefaultTreeCellRenderer has a few variables that determine the text color, background color, selection text color, selection background color, etc. The ones you want to modify to make selection work would be: backgroundSelectionColor and maybe textSelectionColor.
    Another variable is protected boolean selected, if it's true then your node should be highlighted.
    If you look at the DefaultTreeCellRenderer's Constructor it is:
      public DefaultTreeCellRenderer() {
        setHorizontalAlignment(JLabel.LEFT);
        setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
        setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
        setOpenIcon(UIManager.getIcon("Tree.openIcon"));
        setTextSelectionColor(UIManager.getColor("Tree.selectionForeground"));
        setTextNonSelectionColor(UIManager.getColor("Tree.textForeground"));
        setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
        setBackgroundNonSelectionColor(UIManager.getColor("Tree.textBackground"));
        setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
        Object value = UIManager.get("Tree.drawsFocusBorderAroundIcon");
        drawsFocusBorderAroundIcon = (value != null && ((Boolean)value).
                              booleanValue());
        }All it's doing here is gathering the colors specified by your UIManager and storing them in as textSelectionColor, backgroundSelectionColor, etc.
    If you want to use the colors define in your UIManager you don't need to call anything, however if you want to set a certain backgroundSelectionColor like blue, you would call setBackgroundSelectionColor(Color.BLUE) in your constructor (instead of what is up there)...All the constructor does is just store these colors in the DefaultTreeCellRenderer's variables, it does not select or color anything just yet.
    Basically if you want something to be shown as selected you have to look at this function: getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) In my code I made a custom TreeUI which extends BasicTreeUI and in it I override the    protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) function of BasicTreeUI and if the TreePath that is being passed to it is the one I want highlighted I see that the real highlighting occurs when it calls DefaultTreeCellRenderer.getTreeCellRendererComponent()... basically you pass in your JTree, then the node path.getLastPathComponent() that you are currently wanting to paint, then sel (which is set to true if you want that node selected), then expanded (if you want it expanded), leaf (if you want it drawn as a leaf), row (the row that the node resides), and hasFocus (if you've allowed a focus Listener). This function returns to you a Component which you paint using paintComponent - the code for paintRow() is all in BasicTreeUI.java.
    Even though I did all that, all you need to do, if you are calling your custom TreeCellRenderer from you MouseHandler or Listener is setForeground(), the DefaultTreeCellRenderer renders a selected node by calling setForeground(getTextSelectionColor()) and it renders an unselected node by calling setForeground(getTextNonSelectionColor()), it also sets selection (boolean) value to true if your node is supposed to be selected - those things are all done when getTreeCellRendererComponent is called. When paint() is called the node is actually drawn as being selected.
    so in short:
    setTextSelectionColor(Color.WHITE);
    setBackgroundSelectionColor(Color.BLUE);
    setForeground(getTextSelectionColor());  //from getTreeCellRendererComponent();
    selection = true;
    paint(Graphics g);Those are the functions you should look at and hopefully you can get your node highlighted.

  • How to highlight Tree node with a diff color

    I have created tree node and want to highlight Selected node with a different background color. Any Ideas how can we achieve that? -R

    It's an item on page 4 of the application that the blog example is taken from. The tree query:
    SELECT EMPLOYEE_ID AS ID
         , MANAGER_ID  AS PID
         , CASE
             WHEN EMPLOYEE_ID = :P4_EMPLOYEE_ID THEN
                 '<span style="color:white;background-color:blue;">'||
                 LAST_NAME||
                 '</span>'
             ELSE
                 LAST_NAME
           END AS NAME
         , 'f?p=&APP_ID.:4:'||:SESSION||'::NO::P4_EMPLOYEE_ID:'||EMPLOYEE_ID AS LINK
         , NULL        AS A1
         , NULL        AS A2
      FROM #OWNER#.EMPLOYEESgenerates leaf nodes that link to page 4, setting the value of P4_EMPLOYEE_ID. When page 4 is rendered, P4_EMPLOYEE_ID contains the ID of the clicked node, the page displays details of the employee with this ID, and the case expression in the tree query causes the corresponding display value to be highlighted.
    See the sections Managing Session State Values and Using f?p Syntax to Link Pages in the documentation to understand how to set session state values using URLs.
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/concept.htm

  • Selecting a RichTree component tree node

    Hi,
    How do I get the selected tree node in a RichTree component?. I would like to select the node with the mouse and possibly use the popup menu to initiate an action (e.g. delete). How do I add an item to the popup menu to do this? I'm using the RichTree component in JDev 11g. Any sample code would be helpful.
    Thanks
    Colin

    Colin,
    To perform some operation on node selection within af:tree component you simply need to create a selectionlistener and decorate the tree component with the listener you implemented. For the context-menu you describe the af:tree has an attribute named contextMenuId. Set the value of this attribute to equal the id of an af:popup that contains an af:menu that represents the menu that you want displayed on a right-click. Below is a link to the tag doc for the af:tree component
    http://www.oracle.com/technology/products/adf/adffaces/11/doc/multiproject/adf-richclient-api/tagdoc/af_tree.html
    --Ric                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Checking if user has selected or deselected a tree node

    Hello,
    In the event handler of the On Action event of a tree node, I need to decide whether the user has selected the element or deselected it.
    I thought to use the following:
    data:  lo_node type ref to if_wd_context_node,
             lo_element type ref to if_wd_context_element,
             l_element_selected type abap_bool.
    first I tried
    * need to find out if this element was selected or deselected!
      l_element_selected = context_element->is_selected( ).
    but it didn't work - so I tried
    lo_node = context_element->get_node( ).
      lo_element = lo_node->get_lead_selection( ).
      if lo_element = context_element.
        l_element_selected = abap_true.
      else.
        l_element_selected = abap_false.
      endif.
    This did work.
    I'm slightly confused as to why the two did not give the same result?
    I can see in the implementation why - gotta love being able to see how the engine works - but why is the node selection table not set? For future reference, is there some flow that has to happen before the selection gets set but after the lead selection is made? Or is this just an error in the handling of the tree node element?
    Cheers,
    Chris

    One would wonder why there is no is_Lead_Selected method. Having just the is _ Multi_  Selected method is quite confusing. Especially when the method description is "True, if element is selected in the node". One would assume that this would include lead selection.
    Then again - when you consider the mismatch between methods that return values and methods that export values, this lack of a is_Lead_Selected method would be low down on my list of things to fix to make WDA more consistent.
    Having Get_Static_Attributes return the data rather than export it would be much higher on my list - ( get_static_attributes_ref does actually return the reference to the data - talk about inconsistent! )

  • How to calculate the last selected item in a tree node where we can customize the list to the node.

    Hi,
    I'm new to the Flex field. I got a task where i have a tree (TREE is the id) with X and Y as nodes. In X i have got a list of pages(dataprovider is array collection) added dynamically(means User can configure the pages).On selecting last item(last page) in the list of X node, the  view will be presented with a component say Xlast on the right side which is in view stack. In that component , there is button called NEXT which has to be greyed out for the last page. I tried by calling the below code on viewChange event
    if(viewstack.selectedchild == XlastpageId)
    Nextbtn.enabled = false;
    but this will work only when we know XlastpageId is the lastpage for the tree. but how to implement this when we dont know which is the last page of the X node in a Tree.
    I also tried by calculating the children of the tree on tree click event which is
    if (Tree.selectedItem == TREE.numChildren - 1)
    Nextbtn.enabled = false;
    i know this is wrong because we have 2 children for the tree( X and Y) so it is showing 2-1 and the button is greyed out for the first click.
    Please help me out.
    Thanks in Advance,
    Sw

    Hi,
    According to your post, my understanding is that you want to monitor the last login user’s details.
    There is no out of the box way to achieve it in SharePoint.
    We can use cookie to be a flag for checking whether there is an user just log in. After the page loaded, if the cookie is null, it suggests that there is an user just log in our site, then we
    can get this user’s information using JavaScript Object Model and add the information into a custom list. With this list, we can monitor user’s login details.
    Refer to the following link:
    https://social.technet.microsoft.com/Forums/en-US/0cd4d531-cb61-4d90-aa70-413267f4a735/how-to-know-login-and-logout-details-of-a-user-in-sharepoint-online-2013?forum=sharepointdevelopment
    Besides, here are two similar posts for your reference:
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/1a35283e-0f2a-49b8-b330-801a3cfcd890/programatically-get-all-current-logged-in-users-list-for-a-sharepoint-site?forum=sharepointdevelopmentprevious
    https://social.technet.microsoft.com/Forums/en-US/10953be3-cb1c-40c7-9454-545c8338b551/how-to-know-login-users-count-and-their-details-in-sharepoint-2010-web-application?forum=sharepointgeneralprevious
    Best Regards,
    Lisa Chen
    Lisa Chen
    TechNet Community Support

  • Changing the material options for multiple selections doesn't seem to work

    Hi!
    Is it just me or is it not possible to select multiple layers and change their material options like specularity and shininess all at once? Selecting the layers and clicking on cast shadows certainly does work like this, but for some reason when I do the same and change the specularity, it changes only for that layer, regardless of the selection for the other layers.
    Are you able to change material options for multiple layers in one click?

    Works for me... Not sure what else to say. The only thing to consider would be that you need to expose the same properties on all layers or else AE can't match the property streams, so it may be advisable to hit AA to expose all material options instead of just U or UU to reveal changed/ animated properties.
    Mylenium

  • Check Box in Tree (tree multiple selection)

    I need to create a 2 level hierarchy tree, where the user is allowed to make multiple selection on leaf node. One way is to use TableTree (TreeByNestingTableColumn), but with this I am unable to get the same look and feel of a simple Tree view.
    My questions are:
    1. Is there a way to enable multiple selection on a simple Tree?
    2. If the answer to question 1 is no, then is there a way to add check boxes to the Tree elements (be it parent or leaf)?
    3. Is there anything that can be done to solve this issue without using TableTree?
    Thanks in advance.

    Hi,
    Please go through Multiselection in Tree control thread.
    The solution outline is like this:
    1. When you click on a leaf, you mark it as selected and you can also store it in the context.
    2. Click as many leaves as you like and the onAction will mark each of them as selected.
    3. There's no need to do a CTRL+click, only normal clicks.
    4. Once done you can find out all the marked leaves.
    Regards,
    Satyajit.

  • How to copy & paste tree nodes

    Hello,
    Can i have an example that copies & pastes tree nodes?
    thank u.

    It is most probably be cause you are trying to select/deselect an already selected/deselected node programmatically, you need to be careful when using SELECT_ON/OFF if the node is already selected.
    The WHEN-TREE-NODE-SELECTED trigger fires also when a node is deselected, this where the problem exists with this error.
    Use the :SYSTEM..TRIGGER_NODE_SELECTED system variable to determine whether the node is being selected or deselected, it returns 'TRUE' when selected and 'FALSE' when deselected and change your code logic accordingly.
    Metalink Note:292050.1 clearly states the cause of this error
    Tony
    Edited by: Tony Garabedian on Aug 26, 2008 2:08 PM

  • JTree multiple nodes selection problem !

    I can not make my JTree to be in multiple node selection mode.
    I have custom tree model and tree node class, the tree model class
    implements javax.swing.tree.TreeModel, and the tree node is an ordinary
    Java object.
    In this setting, my JTree is always in single selection mode.
    I have tried set the selection model after the JTree has initialized, and
    it didn't work.
    What I missed in TreeModel implementation ? Or should my tree node class
    also implements javax.swing.tree.TreeNode ?
    Don't tell me just call
    xxtree.getSelectionModel().setSelectionMode(javax.swing.tree.TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    It didn't work.

    Just in case anyone wants to know, I did find the magic number of files, and what the problem is. I talked with tech suppot at Adobe, and they know the problem exists, but won't fix it. I did put in a request in the "Request a Feature" form. Read on:
    The magic number is 40 Canon 1Ds Mark III Raw files, and clicking on three or more keywords. The key to not having the numbers of keywords counted incorrectly in the filter pane is to click on the keywords as fast as you can before it starts to write to the metadata. If you click on each keyword one at a time, and wait about a second or more between selecting the keywords, then the counts in the filter panel for the number of keywords is not correct in relation to the number of files that you have chosen to apply keywords to. The cure for this is to click as many keywords as possible as fast as you can before the software starts incorporating the keywords into the metadata.
    I would suggest to Adobe, that a nice feature would be that one could click on as many keywords as one would want, to as many files one would want, and then have a button or icon that would enable one to then apply all the keywords at once, instead of applying them as you click them as it is now. I also would love it if Adobe fixed it now instead of waiting to fix it in the version of CS5. Someone on Adobe's support line told me that Adobe would rather wait to put this into the CS5 version than fix it now. I don't think that is right, but heck, I am only one guy who depends on this software to provide images keyworded to my clients in a timely manner. I would never run my business like this Adobe. If there is a problem, and there is, please fix it now, or give me some of my money back since your product has a design flaw that is having a negative impact in my ability to to my job and run my business.
    Thanks!
    Daniel Root
    Portland, OR

  • How to allow multiple selection of nodes in a JTree

    How to allow multiple selection of nodes in a JTree ?
    Thanks
    S.Satish

    By default when you create new instance og JTree the selection model is multiple selection. And if you want to change it you use next:
    tee.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    or
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
    or
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    Hope will help!

  • Selecting/highlighting a node in Flex Tree using HierarchicalCollectionView as DataProvider

    Hi,
    I am using GroupingCollection2 as the dataprovider for HierarchicalCollectionView. The GroupingCollection2 takes its data from an ArrayCollection. And finally I have a Tree whose dataprovider is the HierarchicalCollectionView . I want to acheive 2 things:
    1) I want to programatically select/highlight a node in this tree. Using expandItem and passing the Object from the arraycollection is not working.
    2) Refresh the tree if there is a change in the arrayCollection.
    For the second task, I have a Java Layer that gives me the ArrayCollection  (dp for GroupingCollection2) when I fire a CairngormEvent. But the problem is that every node in the tree is duplicated. I can clearly see that say there are 8 items in the array collection but still the tree shows 16 items ( Each item duplicated as the node in the tree.)
    I have been trying to figure this out for many days now without any luck. Any sort of suggestion would be appreciated.
    Thank u in advance.

    I got the refreshing of the tree part by myself. One needs to call the refresh method on the GroupingCollection2 and HierarchicalCollectionView objects when the arraycollection has just arrived from the database.
    But I still havent been able to figure out how to highlight or open a tree node programatically. I am repeating that using (calling / setting) tree.expandItem() and tree.openItems is not helping me. Plz somebody help.

  • Af:tree - how do I highlight the selected tree node?

    af:tree
    I checked the generated CSS file. I found that when a tree node is selected, the related CSS attribute is:
    .xj:link{
    font-family:Arial,Helvetica,Geneva,sans-serif;
    font-size:10pt;
    font-weight:normal;
    color:#663300
    I created a customized CSS attribute, but then all of the links have the customized CSS attributes.
    How do I just highlight the selected tree node link?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    try doing the onclick javascript method
    you have to place it on the node element and id must be made dynamic
    for this use 'this.id'
    by which the current id of the node is passed
    and by capturing the id name in a var
    use the same for invoking its selected property and make it true
    like this
    var currentid = this.id;
    this.form.currentid.selected = true;

  • Highlight the selected Tree Node

    Hello Everyone,
    Can someone plz tell me how to highlight the selected tree node ?
    After selection, user should be able to see which node was last selected.
    Thanks

    Hello,
    for me it is not really clear what you have done. Sorry!
    Because I have problems to paste code, I will describe how you can test that function.
    Take the BSP application HTMLB_SAMPLES and copy it to ZHTMLB_SAMPLES. Take page "treeviewSample.htm" and add the following node behind node22:
    <htmlb:treeNode id   = "node23"
                      text = "Node 2.2, normal text"
                      selection="PRIMARYSELECTION">
    Perhaps this will show you how it works and help you.
    As far as I can see the attribute "selection" can't be set via table.
    Best regads
    Renald
    Edited by: Renald Wittwer on Jan 21, 2010 1:36 PM

  • JTree - Sometimes tree node is not selected, while clicking it using mouse

    Hi,
    I'm sure that it is a very rare scenario.But ,sometimes i couldnt select a tree node on mouse click.It happens very rarely and simulating the behaviour is not possible.If anyone have gone thru this,plz repond.
    Thanks,
    Kathir

    did you try debug with a breakPoint on mouseListener->mouseClick event, and see if the selectionModel changes?

Maybe you are looking for