Two values in each node of a JTree

How can i store two values in each treenode of a jtree? The first one is invisible and the second is the one displayed in the tree list.For example, i want to store the id of a database table in the invisible element and a display name in the second.

You don't need any invisible nodes for that. Just create a class that can hold both the id and name, and which will return the name from the toString() method:
public class Pair {
  private String id;
  private String name;
  public Pair(String i, String n) {
    id = i;
    name = n;
  public String getId() { return id; }
  public String getName() { return name; }
  public String toString() { return getName(); } // used by JTree to display the name
}Of course, id and name can be other objects than Strings.

Similar Messages

  • How to select a node in a JTree by name

    I have a JTree in my program. I want to programmatically set one of these nodes selected by the name of the node. I do not know how to do this. I read the "How to use trees", but no help
    Thanks!

    I have a JTree and each node on the JTree has a string name. I also have a JEditorPane that lists all these names at start up. If the user clicks on one of these names, I want to catch the HyperlinkEvent and automatically select that node in the JTree.
    So in short, I have the String name of the node that I want to programatically select.
    Thanks!

  • JTree - need to get the value of a node at a specific node in the tree

    For Example here is a tree:
    Root
    -Item1
    A
    B
    C
    -Item2
    A
    B
    C
    Scenario: Somebody selects B in Item2 from the tree and drags it to a JList. Need to be able to tell the JList that the B came from Item2 and not Item1. So how do I get the Item1, Item2 value? Thanks in advance for all your help.
    Here is the code I am working with...so I have a TreeSelectionEvent(e), a DefaultMutableTreeNode(node) and my JTree(mainTree)
    public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) mainTree.getLastSelectedPathComponent();
    getChildren(node);

    public void valueChanged(TreeSelectionEvent e) {
       javax.swing.tree.TreePath path = e.getPath();
       ...Then use path.getLastPathComponent() and path.getParentPath().getLastPathComponent() methods.
    Tristan

  • With two cursors on just one waveform graph, how can I acquire the X values of each cursor to use them in other functions?

    I can get the x values of each function to display on the front panel with no problems, but I have not been able to acquire this information from the front panel.

    You use a property node to programtically retrieve the cursor values. For each cursor, first use the property Active Cursor to select (0 for the first and 1 for the second) and then the property Cursor Position:Cursor X. See the attachment.
    Attachments:
    cursor_position.jpg ‏212 KB

  • JTree- seperate tooltip for each node

    hi,
    i would like to have different tooltips for different nodes. in all tutorials they have given the method of assinging tooltip in a general class i.e. setting a tooltip for all leaf nodes etc.. But i would like to have seperate tooltip for each node.
    thanx

    hi,
    Doing both of the above tasks will lead to have a tooltip same for all nodes. But i need all the toltips to be different for different leafs.
    However i solved that problem using mouseListeners and getPath() method..
    Now i have another problem. when i move my mouse over any leaf node(not necessarily selecting just on moving over the text) i would like to change the color of the text of that particular node to another color. If i use renderer to do this then it may change the color of all the nodes.
    how it could be done for only a particular node and not for all. Aren't there any renderers for nodes.
    thanx

  • How to use custom nodes in a JTree without reinventing the wheel?

    Hello,
    Each node contains two JTextAreas in a Box layout and a few JButtons.
    I wish to display these nodes in a JTree.
    Reading the tutorial, it seems I would have to reimplement the TreeModel, TreeCellRenderer/Editor, MutableTreeNode interfaces etc.
    Can I use the DefaultTreeModel, and other standard widgets (great stuff!) to minimize the amount of reimplementation I must do. aka avoid reinventing the wheel? I was thinking of extending my node from the DefaultMutableTreeNode class - however it does not display the nodes with the TextAreas, buttons etc.
    any help appreciated.
    thanks,
    Anil

    was able to fix it over here:
    http://forum.java.sun.com/thread.jspa?messageID=4089777

  • Can the name of a specific node in a JTree be returned by MouseEvent?

    I have created a mouseListener for a JTree. When a node in the JTree is clicked it should display the name of the node in a JOptionPane. Currently, I have the following:
    tree.addMouseListener(new MouseAdapter()
    public void mouseClicked(MouseEvent me)
         if(me.getClickCount() % 2 == 0)
         String s = "Blank";
         s = (me.getSource()).toString();
         JOptionPane.showMessageDialog(null, "Double clicked "+ s, "two", JOptionPane.PLAIN_MESSAGE);               
    }//mouseClicked          
    });//MouseListener
    This gives me the class X Y value, border, maxsize, etc.... when a node is double clicked.
    Does anyone know of a better way?

    Don't use MouseListener.
    Instead, make yourself a TreeSelectionListener as follows:
    public class WhererverYourTreeIs implements TreeSelectionListener
         public void valueChanged(TreeSelectionEvent e)
             TreePath path = e.getPath();
             System.out.println(path.getLastPathComponent());
         public void initStuff()
                 tree.addTreeSelectionLIstener(this);
    }

  • Two checkboxes to each item of JList

    I want to take two checkboxes to each item of Jlist
    and depending upon the checkbox state i want to add
    that item in a defferent Jlist

    You don't need any invisible nodes for that. Just create a class that can hold both the id and name, and which will return the name from the toString() method:
    public class Pair {
      private String id;
      private String name;
      public Pair(String i, String n) {
        id = i;
        name = n;
      public String getId() { return id; }
      public String getName() { return name; }
      public String toString() { return getName(); } // used by JTree to display the name
    }Of course, id and name can be other objects than Strings.

  • How do I return two values from a stored procedure into an "Execute SQL Task" within SQL Server 2008 R2

    Hi,
    How do I return two values from a
    stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
    Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
    Something like ?
    CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
    @intPeriod INT,
    @strPeriod_Length NVARCHAR(1),
    @dtStart NVARCHAR(8) OUTPUT,
    @dtEnd NVARCHAR(8) OUTPUT
    AS
    then within the SSIS component; -
    Kind Regards,
    Kieran. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
    Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
    Add a script task to check ssis variables values using,
    Msgbox(Dts.Variables("User::strExtractStartDate").Value)
    Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
    Regards, RSingh

  • How can i add two values under the same property?

    Hi all,
    How can i add two values under the same property name in a
    prop list? For example:
    [question1: "item1","item2", question2: "item3","item4"]
    To be more precise, i am creating a property list and I want
    whenever a two values have the same property name to be added int
    he list under the same property. For example:
    gMyList.AddProp (#""&question&"" & x,
    member("input").text)
    question is a variable that is updated fromt he user's input.
    Now, whenever somethign like this happens:
    question = "question1"
    member("input").text = "five"
    question = "question1"
    member("input").text = "six"
    I want to output list to be:
    [question1: "five","six"] and so on
    Any ideas?

    Maybe you could make each property a list (so you have a
    property list full
    of lists), and add multiple values to the list held in a
    particular
    property?
    Cheers
    Richard Smith

  • How to set Dropdown list in tablen whith others Dropdown values in each row

    how to set Dropdown list in tablen whith others Dropdown values in each row of the table

    hi ,
    You have to add the parent element before adding data to the child node ...you follow the below steps it will work
    1) Take ContextStructure as follows ...
    tabledata (valuenode)
        ddownbyindex( value node) --within the tabledata node
             value (attribute)
    2)Binding to your layout
      tabledata (node) ---bind this to the dataSource property of your  table
          ddownbyindex( node)
                Value (attribute)--bind to the texts property of you DDbyIndex
    3)In wdinit() method add the following code
         IPrivate<Your view name>.ITabledataElement tabledataElement =wdContext.createTabledataElement();
        wdContext.nodeTabledata().addElement(tabledataElement);
        for(int i=0;i<5;i++)
         IPrivate<Your viewname>.IDdownbyindexElement ddbyindexElement=wdContext.createDdownbyindexElement();
             ddbyindexElement.setValue("Value"+i);
             wdContext.nodeDdownbyindex().addElement(ddbyindexElement);
    And set the cardinality property of the table node as 0..n
    and dropdownbyinex node to 1..n
    You try it ...
    Regards
    Madhavi
    Edited by: madhavi kotra on Sep 2, 2008 6:00 PM

  • Hardcode values of the node with cardinality 0..n

    Good day!
    I need to hardcode a list of element to the node with cardinality 0..n.
    Node has two attributes.
    How can I fill the node with a few element in the input mapping? I know I can do it with a single element by separating values by comma. Is it possible to fill the node?

    Hello.
    I've the same problem. Can you say how to set list of values for a structure?
    For example, we've node FIELD containing two attributes:  ID and NAME.
    FIELD is a node with cardinality 0..*. How to set at least two elements to the node?
    Your example works only for simple attributes with cardinality 0..*, but it doesn't work for structures.
    Best Regards,
    Timur Semenchuk.

  • Modify a value of a node

    Hi fellow developers
    I�m trying to modify a value of a node.
    But I think I�m missing something. Please help.
    thanks in advance
    for(int i=0;i<List.getLength();i++){
                        node=List.item(i);
                        if(node.getChildNodes().item(0).getFirstChild().getNodeValue().equals(projectNum)){
                             projectNum = node.getChildNodes().item(0).getFirstChild().getNodeValue();
                             node.getFirstChild().setNodeValue("333");

    Without the dtd, it is not clear why the sample code fails but here are a few pointers that may be of use:
    - The j2ee tutorial on java.sun.com:
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPDOM5.html#wp64575
    has a section on 'examing the structure of a dom' .
    Excerpt for the above URL:
    Note: Important! Text nodes exist under element nodes in a
    DOM, and data is always stored in text nodes. Perhaps the most
    common error in DOM processing is to navigate to an element
    node and expect it to contain the data that is stored in that
    element. Not so! Even the simplest element node has a text
    node under it that contains the data. For example, given
    <size>12</size>, there is an element node (size), and a text
    node under it that contains the actual data (12).
    http://java.sun.com/j2ee/1.4/docs/tutorial/examples/jaxp/dom/samples/DomEcho02.java is a useful program to analyze the structure of a dom.
    - You can try printing the DOM and analyse the structure of DOM. The following URL has a set of useful samples for xml dom processing: http://developers.sun.com/sw/building/codesamples/dom/. In particular the DOMUtils class has two useful static methods for debugging a DOM:
    1. printDOM(org.w3c.dom.Node node): Prints the specified node, then prints all of its children.
    2. writeXmlToFile(java.lang.String filename, org.w3c.dom.Document document): This method writes a DOM document to a file
    http://developers.sun.com/sw/building/codesamples/dom/doc/DOMUtil.java
    - http://forum.java.sun.com/forum.jspa?forumID=34 is the forum for java technology & xml.
    Hope u find the pointers useful.

  • How do I get a dotted line to connect nodes in a JTree?

    I am trying to recreate a Windows Explorer application, does anyone know how they get the dotted lines to connect the nodes in the JTree????

    JTree uses a specific line style to represent the edges between nodes. The default is no edges, but we can set JTree�s lineStyle client property so that each parent node appears connected to each of its child nodes by an angled line:
    myJTree.putClientProperty("JTree.lineStyle", "Angled");
    We can also set this property such that each tree cell is separated by a horizontal line:
    myJTree.putClientProperty("JTree.lineStyle", "Horizontal");
    To disable the line style:
    myJTree.putClientProperty("JTree.lineStyle", "None");
    As with any Swing component, we can also change the UI resource defaults used for all instances of the JTree class. For instance, to change the color of the lines used for rendering the edges between nodes as described above, we can modify the entry in the UI defaults table for this resource as follows:
    UIManager.put("Tree.hash", new ColorUIResource(Color.lightGray))
    Hope this serves your purpose.
    Regards,
    Sachin Shanbhag

  • Highlighting nodes in a JTree

    Hi,
    I'd like to know how I can produce the efect of highlighting nodes in a JTree when the mouse moves over the JTree.
    Thanks

    You say to get the mouseevent coordinates with a mouse
    listener, but which component should be the caller of
    the methos addMouseListener?
    If I choose the jtree, I can't get the 'mouseevent
    coordinates' each time the mouse moves over a node,
    because the methods mouseEntered and mouseExited are
    invoked just once (when the mouse enter inside the
    jtree's area (mouseEntered), and when the mouse gets
    out the jtree's area(mouseExited)), so I can't change
    the boolean field to true for nodes which have the
    mouse over.just use mouseMoved of the MouseMotionListener.
    however, i have my doubts that you will have a lot of fun with the suggested method (correct though it is).
    at least make sure you only call the repaint method if the mouse moved into a new node. you might want to try the the nodeChanged method, that way you don't repaint the whole tree every time.
    thomas

Maybe you are looking for

  • How do I get my wirelss back?  It's greyed out

    I am trying to get my wireless servcie back after upgradeing to 6.0.  I have upgraded to 6.1.1 and still hasnt fixed this.  I have tried resetting netowrk settings on phone, router etc.  Nothing works. Wireless remains greyed out?

  • Question on running multiple clients in production

    We have a question that hopefully someone might be able to clarify for us. We currently have a production SAP landscape consisting on 5 separate SAP clients running on five R/3 4.6c instances on RS6000/Informix and we are looking at alternatives arou

  • Increasing strength and time of vibration notifications

    Help!! I used to own a blackberry and am thinking of returning to it because of the flash and vibrate notifications. I never hear or feel the vibration notificaitions on the iphone 4 and there is no flash option. Is there anything I can do to increas

  • Why does the "alert" noise sound when I open applications?

    When I first got this mac, it did not sound when I opened applications, so it's definitely not normal. I also do not think that this is a type of setting that can be changed, and if it was, I surely did not set it (and nobody else has access to my co

  • CMS Replication issue

    I've started my upgrade from lync 2010 to lync 2013.  I've got my lync 2013 enterprise pilot pool up, certs installed all services running but I cannot get replication working between my  2013 front end servers.  Just not sure where to start troubles