Results 1 to 6 of 6
  1. #1
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default How to invoke a tree as if a node selected ?

    I have a tree and a picture , when user selects a node, a corresponding picture gets updated, that works fine no problem.

    I have also another screen, the same picture gets updated when user selects
    correspoinding area (this is a 3d screen but not important),

    I want my tree "get selected" whenever corresponding node selected from the screen.

    I mean, I want my tree act as if user clicked the node corresponding (the tree opens, and that node get selected, colored etc.)

    In that way, the user will know which node he is clicked when he clicks on teh screen. All I want to invoke my tree simultaneously from other component.

    I hope somebody can provide a solution for this.

  2. #2
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Maybe I am in wrong place. I thought that one will be easy, not rocket science..

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    Use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:
    CODE
    db

  4. #4
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Actually there is no ready code, I just jave a tree, which fire up something on the screen.

    I want also reverse of this, I want to get tree changed, from a button(or any component) as If the user clicked on the tree.

    fo example; lets say that my tree has 3 nodes

    node1

    node2

    node3

    and I ahve 3 J Buttons, as button1, button2, button3
    What I want is;
    If the user clicks button3, I want my tree get opened and get selected node3, as if User actually clicked for node 3 on the tree

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    Do you know how to detect a mouse click?

    Do you know how to set a selection in a tree?

    Put those two together and come up with some code. Or did you really think that someone here would do all your work for you?

    db

    edit
    How to Use Buttons, Check Boxes, and Radio Buttons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    How to Use Trees (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    Last edited by DarrylBurke; 05-10-2011 at 09:41 AM.

  6. #6
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Of course I know these, but I could not find a method like set.

    I have looked interface Interface TreeSelectionModel and its methods
    again I can not find a method for What I want.

    And here is a piece of mode tree code

    TreeModel treemodel = tree.getModel();
    Object TraverseObject = treemodel.getRoot();
    if ((TraverseObject != null) && (TraverseObject instanceof
    DefaultMutableTreeNode)) {
    TreeSelectionListener treeListener = new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
    JTree tree = (JTree) treeSelectionEvent.getSource();
    TreePath object = tree.getSelectionPath();


    Actulay this tree reads information from an xml and sets up. Tree is working , no problem, what I want is as I have told before,

    I have my tree get selected as if user, when user fires sth from other component.
    I just need which method for this because I could it find it in anywhere..

Similar Threads

  1. Replies: 0
    Last Post: 04-17-2011, 05:57 PM
  2. How to sample a node from a binary tree efficiently?
    By malaguena in forum Advanced Java
    Replies: 0
    Last Post: 03-12-2011, 06:57 PM
  3. How to capture a tree node edit ?
    By ni4ni in forum AWT / Swing
    Replies: 1
    Last Post: 03-11-2011, 06:21 AM
  4. Get selected Node Value of a child element
    By Ms.Ranjan in forum XML
    Replies: 6
    Last Post: 10-06-2009, 10:31 PM
  5. How to print selected items in a SWT tree
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 05:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •