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.

Similar Messages

  • 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

  • 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 );

  • How to highlight/indicate particular tree Node in Tree UI element

    Hi All
    Can anybody let us know how to highlight/indicate specific node in a tree struture.
    currently i am able to display the tree struture with all the nodes & elements but it is always tasking firstnode as highlighted one or indicated one.
    if i want to highlight specific node in a tree struture...what was the procedure or any sample code then it would be great help to us.
    Thanks
    Trisha rani

    Hi Krishna
    Thanks for your reply
    I displayed the tree structure and i want to highlight specific parent node/child element , what was the sample code??
    for example my tree was displayed in the below struture and at the runtime specific child node i wanted to be highlighted i want to make selectable particular nodeType......
    Can you pls send sample codee code??
    my requirement
    A
    A1
       A2
       A3
    B
    B1      
       B2
       B3
       B4
       B5     
    now i want to make selectable or highlighted B4,B5 etc  or A2,A3 at runtime.
    The other guy who replied for this thread it is working for Parent nodes to make highlighted  like it is working for parent nodes which is have child nodes. i am able to hightlight at runtime for Nodes A,B etc .
    Now i want to highlight or make selected one for B4,A3 etc, pls provide sample code??
    it  would be great help to us
    Thanks
    Trisha Rani

  • 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.

  • How to highlight a tree node programmatically

    Problem
    =====
    Just like a typical management software, I have a navigation tree presenting a list of objects (let's say toasters) on the left panel. The content panel on the right side presents the details of a toaster, when the user selects the toaster on the navigation tree. On the toaster details panel, I would like to have a hyper link referring to another toaster - associated to the selected toaster. On clicking on the hyperlink, I would like to display the details of the associated toaster and the navigation tree node for the associated toaster being highlighted.
    For example, BUI presents the following now:
    + Toasters | Toaster 1 Details [Refresh]
    + <toaster1> |
    + toaster2 | ... toaster3
    + toaster3 |
    toaster1 is selected on the navigation tree. The contents panel displays Toaster 1 details, which has a hyper link for toaster3.
    When the user click on toster3 on the contents panel, I would like to see the following
    + Toasters | Toaster 3 Details [Refresh]
    + toaster1 |
    + toaster2 | ...
    + <toaster3> |
    My Trial
    =====
    ADF Rich Client 11.1.2.3 is used for my development.
    Jspx code for the navigation tree looks like this:
    <af:tree id="navTree" ...>
    <f:facet name="nodeStamp">
    <af:panelGroupLayout id="nodePgl">
    <af:switcher facetName="#{stamp.outcome!=null?'actnode':'noactnode'}" ...>
    <f:facet name="actnode">
    <af:commandLink id="leafLink" text="#{stamp.label}" action="#{stamp.actionOutcome}">
    <af:setActionListener from="#{stamp.key}" to="#{treeHandler.selectedMenuItem}"/>
    </af:commandLink>
    </f:facet>
    <f:facet name="noactnode">
    <af:outputText id="notLeafText" value="#{stamp.label}"/>
    </f:facet>
    </af:switcher>
    </af:panelGroupLayout>
    </f:facet>
    </af:tree>
    The hyper link on the contents panel looks like this:
    <af:iterator var="toaster" value="#{toastData.toasters}">
    <af:commandLink text="#{toaster}" action="#{toasterHandler.goToToaster}">
    <f:param name="toasterId" value="#{toaster}"/>
    <af:setActionListener from="#{toaster}" to="#{treeHandler.selectedToaster}"/>
    </af:commandLink>
    </af:iterator>
    I got some tips from this forum (cannot find thread at the moment) and implemented the treeHandler.selectedToaster method as follows:
    // getSelectionState returns selStat, which is instantiated like the following:
    // RowKeySet selStat = new RowKeySetTreeImpl();
    // TreeModel model = (TreeModel) menuModel.getWrappedData();
    // selStat.setCollectionModel(model);
    // selStat.setContained(true);
    RowKeySet rowKeySet = getSelectionState();
    rowKeySet.removeAll();
    // synthesize the rowKey for the selected toaster
    // if the toaster found in the toaster node list,
    // rowKey should look like [0, <rowIdx of toaster>]
    ArrayList<Integer> rowKey = new ArrayList<Integer>();
    rowKey.add(0);
    rowKey.add(new Integer(rowIdx));
    TreeModel model = (TreeModel) menuModel.getWrappedData();
    model.setRowKey(rowKey);
    model.setRowIndex(rowIdx);
    rowKeySet.add();
    This seems to work most of times except when I refresh the contents details panel using partial page rendering.
    I get NullPointerException on the call to rowKeySet.removeAll().
    Caused by: java.lang.NullPointerException
         at org.apache.myfaces.trinidad.model.RowKeySetTreeImpl._selectAll(RowKeySetTreeImpl.java:459)
         at org.apache.myfaces.trinidad.model.RowKeySetTreeImpl.removeAll(RowKeySetTreeImpl.java:146)
    In my observation, this NPE happens when rowKeySet.size() returns 1 but rowKeySet.iterator() does not return any entries.
    I suspect this is a bug on RowKeySetTreeImpl but not sure.
    Help Need
    =======
    1. What is the reasonably right way to highlight the tree node for my problem?
    2. If my trial is one way to do it, how can I get around the NPE? I cannot change ADF Rich Client library at this point.
    Any help/suggestion/advise would be appreciated.
    Thanks,
    Jeongtae

    I did this, to programmatically expand a tree node, you can try the same and set the row key to highlight.
    private RowKeySet disclosedTreeRowKeySet = new RowKeySetImpl();
    public void rowDisclosureListener(RowDisclosureEvent rowDisclosureEvent)
    Iterator added = rowDisclosureEvent.getAddedSet().iterator();
    if (added!=null)
    while (added.hasNext())
    Object rowKey = added.next();
    //disclosedTreeRowKeySet.clear();
    List path = (List)rowKey;
    for( int i=0; i< path.size(); i++ )
    List<Object> nodePath = new ArrayList<Object>();
    for( int j=0; j<i; j++ )
    nodePath.add( path.get( j ) );
    disclosedTreeRowKeySet.add( nodePath );
    disclosedTreeRowKeySet.add( rowKey );
    System.out.println( "disclosed Keys...... " + disclosedTreeRowKeySet );
    private void expandSelectedNode(RowKeySet addedObj) {
    if (sourceTreeTable != null) {
    Iterator added = (Iterator)addedObj.iterator();
    if (added!=null)
    while (added.hasNext())
    Object rowKey = added.next();
    List path = (List)rowKey;
    for( int i=0; i< path.size(); i++ )
    List<Object> nodePath = new ArrayList<Object>();
    for( int j=0; j<i; j++ )
    nodePath.add( path.get( j ) );
    disclosedTreeRowKeySet.add( nodePath );
    disclosedTreeRowKeySet.add( rowKey );
    sourceTreeTable.setDisclosedRowKeys(disclosedTreeRowKeySet);
    }

  • Highlight an ADF tree node when it is clicked

    Hello every onei ,
    Does anybody has any idea how to highlight an ADF tree node when it is clicked ?
    Here is my scenario:-
    I have a popup which has a tree component on left and when we click on any node in the tree we have to display the corresponding page on right side.
    As the tree is common for all pages in the popup, i created an XHTML template with tree. All the treenode pages will use this template to display the tree.This template i am using to implement in rest of the pages.
    So when i click any link on this tree will load the corresponding JSP. But i am loosing focus. i mean selected node is not highlighting. Because we are loading the entire target page with template.
    Could any let me know how to highlight the tree node ?
    The Main problem is we are not using ADF controllers. We are using managed beans, these managed beans attached to the JSPX pages.
    Kindly guide me if any one knows solution.
    Thanks & Regards,
    Sai Sravan.P

    Hello Sai,
    I am afraid you have posted your question in the wrong forum. This forum is about Oracle On Track Communication, a next-generation social enterprise collaboration product.
    Please re-post your question in an ADF related forum and I am sure someone will be able to answer.
    Thank you,
    Ernst.

  • 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

  • How to highlight a node in a tree?

    i used setSelectionPath() . But it is highlighting the node's icon only(i.e by changing the color to lavender). I'm getting higlighted the node with setSelectionInterval(ind,ind) only. I want that higlighlighting to be with setselectionPath() . How to do?
    Appreciating any help
    Thanks.

    When I do a setSelectionPath the node-text is highlighted, not the icon. Anyways, do a custom treecellrenderer like this:
    public Component getTreeCellRendererComponent(.......) {
    if(selected == true) setBackground(somecolor)
    else setBackground (defaultcolor)
    if that describtion isnt sufficient try search the forum.

  • Tree and Tree Node Components - Threadinar7

    Hi All,
    This is the seventh in the "Threadinar" series , please see Threadinar6 at
    http://forum.sun.com/jive/thread.jspa?threadID=100601 for details
    In this Threadinar we will focus on the
    "Tree" and "Tree Node" Components
    Let us begin our discussion with the Tree Component.
    Tree Component
    You can drag the Tree component from the Palette's Basic category to the Visual Designer to create a hierarchical tree structure with nodes that can be expanded and collapsed, like the nodes in the Outline window. When the user clicks a node, the row will be highlighted. A tree is often used as a navigation mechanism.
    A tree contains Tree Node components, which act like hyperlinks. You can use a Tree Node to navigate to another page by setting its url property. You can also use a Tree Node to submit the current page. If the the Tree Node's action property is bound to an action event handler, selecting the node automatically submits the page. If the Tree Node's actionListener property is bound to an action listener, opening or closing the node automatically submits the page. You set Tree Node properties in the Tree Node Component Properties window.
    * If you use this component to navigate between pages of a portlet, do not use the url property to link to a page. Instead, use the Navigation editor to set up your links to pages.
    * Events related to tree node selection do not work correctly in portlets because the component uses cookies to pass the selected node id back and forth, and cookies are not correctly handled by the portlet container. You cannot handle tree node selection events in portlet projects.
    Initially when you drop a tree on a page, it has one root node labeled Tree and one subnode labeled Tree Node 1. You can add more nodes by dragging them to the tree and dropping them either on the root node to create top level nodes or on existing nodes to create subnodes of those nodes. You can also right-click the Tree or any Tree Node and choose Add Tree Node to add a subnode to the node.
    Additionally, you can work with the component in the Outline window, where the component and its child components are available as nodes. You can move a node from level to level easily in the Outline window, so you might want to work there if you are rearranging nodes. You can also add and delete tree nodes in the Outline window, just as in the Visual Designer.
    The Tree component has properties that, among other things, enable you change the root node's displayed text, change the appearance of the text, specify if expanding or collapsing a node requires a trip to the server, and specify whether node selection should automatically open or close the tree. To set the Tree's properties, select the Tree component in your page and use the Tree Component Properties window.
    The following Tutorial ("Using Tree Component") is very useful to learn using Tree components
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/sitemaptree.html
    See Also the Technical Article - "Working with the Tree Component and Tree Node Actions"
    http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/tree_component.html
    Tree Node Component
    You can drag the Tree Node component from the Palette's Basic category to a Tree component or another tree node in the Visual Designer to create a node in a hierarchical tree structure, similar to the tree you see in the Outline window.
    The tree node is created as a subnode of the node on which you drop it. If you drop the node on the tree component itself, a new node is created as a child of the root node. You can see the hierarchical structure clearly in the Outline window, where you can also easily move nodes around and reparent them.
    You can also add a tree node either to a Tree component or to a Tree Node component by right-clicking the component and choosing Add Tree Node.
    A Tree Node component by default is a container for an image and can be used to navigate to another page, submit the current page, or simply open or close the node if the node has child nodes.
    * If you select the Tree Node component's node Tree Node icon in the Outline window, you can edit its properties in the Tree Node Properties window. You can set things like whether or not the Tree Node is expanded by default, the tooltip for the Tree Node, the label for the tree node, and the Tree Node's identifier in your web application.
    * You can use a Tree Node to navigate to another page by setting its url property. You can also use a Tree Node to submit the current page. If the the Tree Node's action property is bound to an action event handler, selecting the node automatically submits the page. If the Tree Node's actionListener property is bound to an action listener, opening or closing the node automatically submits the page.
    - Note: If you use this component to navigate between pages of a portlet, do not use the url property to link to a page. Instead, use the Navigation editor to set up your links to pages. In addition, events related to tree node selection do not work correctly in portlets because the component uses cookies to pass the selected node id back and forth, and cookies are not correctly handled by the portlet container. You cannot handle tree node selection events in portlet projects.
    * If you select the image in the Tree Node, you can see that its icon property is set to TREE_DOCUMENT. If you right-click the image on the page and choose Set Image, you can either change the icon to another one or choose your own image in the Image Customizer dialog box. For more information on working with an image in a tree node, see Image component.
    - Note: The image used in a tree node works best if it is 16x16 or smaller. Larger images can work, but might appear overlapped in the Visual Designer. You can right-click the component and choose Preview in Browser feature to check the appearance of the images.
    Please share your comments, experiences, additional information, questions, feedback, etc. on these components.
    ------------------------------------------------------------------------------- --------------------

    One challenge I had experience was to make the tree
    always expanded on all pages (I placed my tree menu
    in a page fragment so I can just import it in my
    pages).Did you solve this problem. It would be interesting to know what you did.
    To expand a node you call setExpanded on the node. Here is some code from a tutorial that a coworker of mine is working on.
    In the prerender method:
           Integer expandedPersonId = getRequestBean1().getPersonId();
             // If expandedPersonId is null, then we are not coming back
            // from the Trip page. In that case we do not want any trip
            // nodes to be pre-selected (highlighted) due to browser cookies.
            if (expandedPersonId==null) {
                try {
                    HttpServletRequest req =(HttpServletRequest)
                    getExternalContext().getRequest();
                    Cookie[] cookies = req.getCookies();
                    //Check if cookies are set
                    if (cookies != null) {
                        for (int loop =0; loop < cookies.length; loop++) {
                            if (cookies[loop].getName().equals
                                    ("form1:displayTree-hi")) {
                                cookies[loop].setMaxAge(0);
                                HttpServletResponse response =(HttpServletResponse)
                                getExternalContext().getResponse();
                                response.addCookie(cookies[loop]);
                } catch (Exception e) {
                    error("Failure trying to clear highlighting of selected node:" +
                            e.getMessage());
            }                  ... (in a loop for tree nodes)...
                      personNode.setExpanded(newPersonId.equals
                                    (expandedPersonId));In the action method for the nodes:
           // Get the client id of the currently selected tree node
            String clientId = displayTree.getCookieSelectedTreeNode();
            // Extract component id from the client id
            String nodeId = clientId.substring(clientId.lastIndexOf(":")+1);
            // Find the tree node component with the given id
            TreeNode selectedNode =
                    (TreeNode) this.getForm1().findComponentById(nodeId);
            try {
                // Node's id property is composed of "trip" plus the trip id
                // Extract the trip id and save it for the next page
                Integer tripId = Integer.valueOf(selectedNode.getId().substring(4));
                getRequestBean1().setTripId(tripId);
            } catch (Exception e) {
                error("Can't convert node id to Integer: " +
                        selectedNode.getId().substring(4));
                return null;
    It would also be great if I can set the tree
    readonly where the user cannot toggle the expand
    property of the tree (hope this can be added to the
    tree functionality).

  • Select tree node in tree component

    hi,
    i am developing a web site which has a site map as a tree component, the sitemap is a inserted in a page fragment, users could click tree nodes to go to corresponding pages. also on other pages, i have next and previous buttons which allow users to navigate through pages. the question is how can i update the tree component when users navigate using the next and previous buttons so that the correct tree node is highlighted?
    i tried to use the selected property for the tree component, but it does not do anything.
    thanks,
    lee

    Hi,
    Duplicate thread of
    http://swforum.sun.com/jive/thread.jspa?threadID=64518
    MJ

  • WD ABAP: selecting a tree node from program and scroll to it

    Hi guys!
    I am using a tree in Web Dynpro ABAP. I would like to select/highlight one node from the coding, without user interaction. Is it possible? I couldn't find any (obvious) way so far...
    If it is possible, then let us go a little bit further. Suppose, that the tree grew so big, that cannot fit in the container. Suppose, that you can scroll the tree up/down to see all the nodes. Now, if you mark one tree node from the coding, is it possible somehow, that you scroll the tree automatically, so that the selected node is visible?
    I am interested in any solutions within WD ABAP.
    If you can only answer one of the questions, that is also appreciated!
    Thanks for the help in advance.
    Best regards,
    Janos Kis
    Aerospace&Defense(ERP)

    Hi Thomas,
    thanks for the advice, it works, I have already tried it. The tree node in the lead selection appears highlighted.
    The scrolling doesn't work, though. I have tried to put the tree in a scroll container, and I have also tried it without (relying on the browser to scroll). Neither of them worked, it doesn't scroll to the selected node, it remains offscreen. Can you think of a way, to bring it automatically within the visible range? Ideas, anyone?
    Actually we would like to implement a search function in the tree, and show the result within the tree (highlight the node, expand, if necessary, and bring it on the screen, if off-screen)
    A negative answer is good enough for me, so that I know, that I can stop looking for a solution. Thanks in advance.
    Janos

  • Highlight root node in jtree

    When I build my JTree, I have just one single node, the root node. So in order to highlight it, I basically do setSelectionRow(0);, however this is not highlighting the node as if a user clicked it with a mouse, WHEN THE APPLICATION COMES UP.
    Once the application comes up, if I click on that node or for that matter any other node, they get highlighted in blue. It's only upon initialization that this doesn't work.
    Here's a snippet of the sample code:
    tree = new JTree();
    tree.setCellRenderer(new RateManagerTreeCellRenderer());
    I've also tried the setSelectionPath(TreePath path) method without any success. I think that my Custom TreeCellRenderer could be the culprit. If someone could try to duplicate this problem by using the code below of my RateManagerTreeCellRenderer, I would appreciate it.
    public class RateManagerTreeCellRenderer extends DefaultTreeCellRenderer
    private static Color oldColor = Color.BLACK;
    private static Color newColor = Color.BLUE;
    private HashMap iconMap = new HashMap();
    public Component getTreeCellRendererComponent(
              JTree tree, Object value,
              boolean selected, boolean expanded,
              boolean leaf, int row,
              boolean hasFocus)
    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value;
    Object userObject = treeNode.getUserObject();
    if (userObject instanceof NameAndID)
    NameAndID nameAndID = (NameAndID)userObject;
    int count = nameAndID.getItemCount();
    if (count > 0 && !selected)
    setForeground(newColor);
    else if (!selected)
    setForeground(oldColor);
    this.setToolTipText(((NameAndID)userObject).toString());
    String type = nameAndID.getType();
    setIcon(type);
    return this;
    }

    Do you mean setting the focus on that node? Or are you talking about some custom painting to put a background behind it? We can't help you much if you don't ask a more specific question with more details about what you're trying to do.

  • Determine if mouse is over tree node

    hi.
    I recently added some code from this forum on
    highlighting a node when the mouse is over it.
    I am taking this futher and setting a Border around the nodehowever it draws a border around every node.
    I want to only draw the border when the mouse is over the node.
    the example i got does this to set the foreground
    ((JLabel)result).setForeground(Color.red);
    i do this to set the border
    ((JLabel)result).setBorder
    (BorderFactory.createLineBorder(Color.black));
    i ve tried getting the positions of both the mouse and the jlabel but am having trouble determining if the position of the mouse is within the position of the node in the tree.
    Ive used methods like the contains method but it doesnt work for me . can anyone give me a hint as to how to see if the points of the mouse are on the Jlabel?

    This is very close to your solution. Last month, I implement ToolTip Text on every Tree Node so when Mouse goes on to the Node, It shows the Tool Tip Text. Have a look at this code and try to change it accordingly.
    This code is in the Constructor in your class.
    tree.setCellRenderer(new IDETreeCellRenderer());
    tree.setToolTipText("");Class: IDETreeCellRenderer - Cell Renderer for the Tree
    package tv.izone.ide.tree;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import tv.izone.core.*;
    import tv.izone.ide.guiutilities.*;
    import tv.izone.izml.data.*;
    public class IDETreeCellRenderer
        extends DefaultTreeCellRenderer {
       DefaultTreeCellRenderer label;
        * Override TreeCellRendererComponent, used for changing Tree Node for comments.
        * @param tree Tree to be used
        * @param value Value of the Node
        * @param selected true, if selected
        * @param expanded true, if expanded
        * @param leaf true, if it is a leaf
        * @param row Row Number
        * @param hasFocus True, if has Focus
        * @return Component, Tree
       public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
                                      boolean leaf, int row, boolean hasFocus) {
          try {
          label = (DefaultTreeCellRenderer)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                                                      hasFocus);
          label.setToolTipText(dataObject.getToolTipText());
    // Instead of setToolTipText(), try setBackgroundColor() or setBorder()
         return label;
          } catch (Exception ex) {
          // NullPointerException, usually comes at the start of the Application
          // when the Tree is empty.
          return this;
    }Hope this Helps
    Regards
    Raheel

Maybe you are looking for

  • How to Install NetWeaver 7.3 Developer Studio On AIX/Oracle

    Hello All- I am trying to install Developer Workpace for 7.30 , I have already downloaded the installation guide for SAP NetWeaver 7.30 from SAP Market placehttps://websmp202.sap-ag.de/~form/sapnet?_FRAME=CONTAINER&_OBJECT=011000358700001302862010E.

  • Open external URL from Homepage Framework

    Hi, We are building our new ESS functionality with Homepage Framework and I need to create some links to external URL. I would like them to open in a different window with no portal header at all. They should appear as services listed in the menu are

  • New layer for each artboard

    Hi, I've just recently started learning Illustrator and have used photoshop for a long time.  I have been getting on OK and yesterday had a file open with about 4 different artboards (was making wedding invitations) and went to start a 5th one and de

  • Png file inside Premiere Pro CS4 project - export video problem

    Hi I've got a strange problem with Premiere CS4. I have a project with two layers. First (bottom) is with video material on it, and on second one (top) has a transparent PNG file. Preview looks great but after exporting it to uncompressed AVI theres

  • Archsetup exitting with error. Install package step

    I set the packages I want (I need wireless capabilities) and when I go to the install packages step the installer exits with the errors cat: /tmp/aif/aif-pacman_installpkg-exit: No such file or directory rm: cannot remove '/tmp/air/aif-pacman_install