Results 1 to 5 of 5

Thread: How to use a Tree Expansion Listener in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    287

    How to use a Tree Expansion Listener in Java?

    Hi friends,
    I am posting this query for the first time on this forum. So please don't overlook it. I am trying to use tree expansion listener because I have used the Tree. Now I need to react when a branch becomes expanded or collapsed, so I want to use that listener. Please help me by telling how to use a Tree Expansion Listener in Java.?? Expecting some help soon as possible.!!
    Dimension 1100 (FMY032J) mini-tower
    2.53ghz Intel Pentium 4
    80 gig nfts HDD
    512 RAM
    Main circuit board: Dell 0CF458
    BIOS: Dell A00
    Display: Intel(R) 82865G Graphics Controller [Display adaptor]
    Multimedia: Sound MAX Integrated Digital Audio
    Windows XP Home SP2

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to use a Tree Expansion Listener in Java?

    There are some scenarios when you need to react when a branch becomes expanded or collapsed, at such times using tree expansion listener would be useful. But before going for the listener, you must know better about the using the tree in Java. You can display hierarchical data by using the JTree class. You will get more information about the writing Trees in Java on the following link :
    How to use Trees in Java?
    Hope that it helps you.!!!

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use a Tree Expansion Listener in Java?

    I think that you should know more about the methods that are used by the Tree Expansion Listener to clear your concepts. You should keep in mind that TreeExpansionListener has no adapter class. The following are the methods used by the TreeExpansionListener Interface :
    • treeCollapsed(TreeExpansionEvent) - This method is called just after a tree node collapses.
    • treeExpanded(TreeExpansionEvent) - After a tree node expands, this method is called.

  4. #4
    Join Date
    Jul 2006
    Posts
    286

    Re: How to use a Tree Expansion Listener in Java?

    Before doing the coding, you should also know the methods that are used by the TreeExpansionEvent API. The following are the methopds of the same :
    • Object getSource() - This method returns the object that fired the event.
    • TreePath getPath() - This method returns a TreePath object that identifies each node from the root of the tree. This also returns the collapsed or expanded node.

    Hope you will get some help from this.!!
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  5. #5
    Join Date
    Jul 2006
    Posts
    442

    Re: How to use a Tree Expansion Listener in Java?

    I have provided you with following code that shows how the program handles expansion events :
    Code:
    public class TreeExpandTrial ... {
        ...
        void saySomething(String eventDescription, TreeExpansionEvent te) {
            textArea.append(eventDescription + "; "
                            + "path = " + te.getPath()
                            + newline);
        }
    
        class DemoArea ... implements TreeExpansionListener {
            ...
            public DemoArea() {
                ...
                tree.addTreeExpansionListener(this);
                ...
            }
            ...
            public void treeExpanded(TreeExpansionEvent te) {
                saySomething("Tree-expanded event detected", te);
            }
    
            public void treeCollapsed(TreeExpansionEvent te) {
                saySomething("Tree-collapsed event detected", te);
            }
        }
    }
    "When they give you ruled paper, write the other way..." J.R.J.

Similar Threads

  1. Own Event Listener in Java
    By Messenger in forum Software Development
    Replies: 6
    Last Post: 13-08-2010, 10:20 AM
  2. What is Mouse-Motion Listener in Java?
    By Bigga Lexx in forum Software Development
    Replies: 4
    Last Post: 13-02-2010, 05:35 AM
  3. How to write a Key Listener in Java?
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 01:52 AM
  4. How to write a Focus Listener in Java?
    By The Recruiter in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 07:05 AM
  5. How to write a Container Listener in Java?
    By Pratim in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 06:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,006,770.31582 seconds with 17 queries