Results 1 to 6 of 6
  1. #1
    msambasiva is offline Member
    Join Date
    Jun 2013
    Posts
    18
    Rep Power
    0

    Default SwiXML - JTree LazyLoad Expand listener issue

    Hi,



    Iam creating UI using SwiXML which is based on Swing. Able to create a Tree structure using the below code logic. Issue is, unable to invoke expansion listener method.

    It would be great, if you can suggest on this issue.



    We have configured Java file in a xml file as below
    <scrollpane id="neh_task_tree">
    <gridbagconstraints insets="5,5,5,5" gridx="1" gridy="1" weightx="1.0"
    weighty="1.0" fill="GridBagConstraints.BOTH"
    anchor="GridBagConstraints.WEST"/>
    <tree id="neh_prod_activity_task_tree" initclass="com.oracle.appsfdoc.fusion.sos.LazyLoad Demo" Font="ARIAL-BOLD-14" VisibleRowCount="5"/>
    </scrollpane>







    public class LazyLoadDemo extends DefaultTreeModel {

    JTree tree;

    final TreeNode root;

    public LazyLoadDemo() {

    super(new DefaultMutableTreeNode("ROOT"));

    System.out.println("LazyLoadDemo");

    root = (DefaultMutableTreeNode) super.getRoot();

    createNodes(root);

    tree = new JTree((TreeNode)root);

    //tree.addTreeExpansionListener(this);

    //tree.addTreeWillExpandListener(this);

    System.out.println("BEFORE HANDLER");

    tree.addTreeExpansionListener(new TreeExpansionListener(){



    @Override

    public void treeCollapsed(TreeExpansionEvent e)

    {

    System.out.println("Node collapsed at " + e.getPath() + "\n");

    }



    @Override

    public void treeExpanded(TreeExpansionEvent e)

    {

    System.out.println("Node expanded at " + e.getPath()+ "\n");

    }



    }); System.out.println("AFTER HANDLER");

    }

    private void treeForumReviewTreeExpanded(javax.swing.event.Tree ExpansionEvent evt) {//GEN-FIRST:event_treeForumReviewTreeExpanded

    // TODO add your handling code here:

    System.out.println("treeForumReviewTreeExpanded");

    /*DefaultMutableTreeNode node = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();

    ForumView fv = (ForumView) node.getUserObject();

    refreshReview(fv);*/

    }

    private TreeNode createNodes(TreeNode root) {

    DefaultMutableTreeNode grandparent;

    DefaultMutableTreeNode parent;

    DefaultMutableTreeNode child;

    DefaultMutableTreeNode temp = (DefaultMutableTreeNode)root;

    root = new DefaultMutableTreeNode("San Francisco");



    grandparent = new DefaultMutableTreeNode("Potrero Hill");

    temp.add(grandparent);

    //

    parent = new DefaultMutableTreeNode("Restaurants");

    grandparent.add(parent);

    child = new DefaultMutableTreeNode("Thai Barbeque");

    parent.add(child);

    child = new DefaultMutableTreeNode("Goat Hill Pizza");

    parent.add(child);

    //

    parent = new DefaultMutableTreeNode("Grocery Stores");

    grandparent.add(parent);

    child = new DefaultMutableTreeNode("Good Life Grocery");

    parent.add(child);

    child = new DefaultMutableTreeNode("Safeway");

    parent.add(child);



    grandparent = new DefaultMutableTreeNode("Noe Valley");

    temp.add(grandparent);

    //

    parent = new DefaultMutableTreeNode("Restaurants");

    grandparent.add(parent);

    child = new DefaultMutableTreeNode("Hamano Sushi");

    parent.add(child);

    child = new DefaultMutableTreeNode("Hahn's Hibachi");

    parent.add(child);

    //

    parent = new DefaultMutableTreeNode("Grocery Stores");

    grandparent.add(parent);

    child = new DefaultMutableTreeNode("Real Foods");

    parent.add(child);

    child = new DefaultMutableTreeNode("Bell Market");

    parent.add(child);



    return root;

    }

    }



    Thanks in advance,
    Samba.

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

    Default Re: SwiXML - JTree LazyLoad Expand listener issue

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    msambasiva is offline Member
    Join Date
    Jun 2013
    Posts
    18
    Rep Power
    0

    Default Re: SwiXML - JTree LazyLoad Expand listener issue

    Created [CODE] blocks as per your suggestion. Please suggest, if you still have any comments on the post.

    Thanks,
    Samba.

    Java Code:
    <scrollpane id="neh_task_tree">
    <gridbagconstraints insets="5,5,5,5" gridx="1" gridy="1" weightx="1.0"
    weighty="1.0" fill="GridBagConstraints.BOTH"
    anchor="GridBagConstraints.WEST"/>
    <tree id="neh_prod_activity_task_tree" initclass="com.oracle.appsfdoc.fusion.sos.LazyLoad Demo" Font="ARIAL-BOLD-14" VisibleRowCount="5"/>
    </scrollpane>
    Java Code:
    public class LazyLoadDemo extends DefaultTreeModel {
    
    JTree tree;
    
    final TreeNode root;
    
    public LazyLoadDemo() {
    
    super(new DefaultMutableTreeNode("ROOT"));
    
    System.out.println("LazyLoadDemo");
    
    root = (DefaultMutableTreeNode) super.getRoot();
    
    createNodes(root);
    
    tree = new JTree((TreeNode)root);
    
    //tree.addTreeExpansionListener(this);
    
    //tree.addTreeWillExpandListener(this);
    
    System.out.println("BEFORE HANDLER");
    
    tree.addTreeExpansionListener(new TreeExpansionListener(){
    
    
    
    @Override
    
    public void treeCollapsed(TreeExpansionEvent e)
    
    {
    
    System.out.println("Node collapsed at " + e.getPath() + "\n");
    
    }
    
    
    
    @Override
    
    public void treeExpanded(TreeExpansionEvent e)
    
    {
    
    System.out.println("Node expanded at " + e.getPath()+ "\n");
    
    }
    
    
    
    }); System.out.println("AFTER HANDLER");
    
    }
    
    private void treeForumReviewTreeExpanded(javax.swing.event.Tree ExpansionEvent evt) {//GEN-FIRST:event_treeForumReviewTreeExpanded
    
    // TODO add your handling code here:
    
    System.out.println("treeForumReviewTreeExpanded");
    
    /*DefaultMutableTreeNode node = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();
    
    ForumView fv = (ForumView) node.getUserObject();
    
    refreshReview(fv);*/
    
    }
    
    private TreeNode createNodes(TreeNode root) {
    
    DefaultMutableTreeNode grandparent;
    
    DefaultMutableTreeNode parent;
    
    DefaultMutableTreeNode child;
    
    DefaultMutableTreeNode temp = (DefaultMutableTreeNode)root;
    
    root = new DefaultMutableTreeNode("San Francisco");
    
    
    
    grandparent = new DefaultMutableTreeNode("Potrero Hill");
    
    temp.add(grandparent);
    
    //
    
    parent = new DefaultMutableTreeNode("Restaurants");
    
    grandparent.add(parent);
    
    child = new DefaultMutableTreeNode("Thai Barbeque");
    
    parent.add(child);
    
    child = new DefaultMutableTreeNode("Goat Hill Pizza");
    
    parent.add(child);
    
    //
    
    parent = new DefaultMutableTreeNode("Grocery Stores");
    
    grandparent.add(parent);
    
    child = new DefaultMutableTreeNode("Good Life Grocery");
    
    parent.add(child);
    
    child = new DefaultMutableTreeNode("Safeway");
    
    parent.add(child);
    
    
    
    grandparent = new DefaultMutableTreeNode("Noe Valley");
    
    temp.add(grandparent);
    
    //
    
    parent = new DefaultMutableTreeNode("Restaurants");
    
    grandparent.add(parent);
    
    child = new DefaultMutableTreeNode("Hamano Sushi");
    
    parent.add(child);
    
    child = new DefaultMutableTreeNode("Hahn's Hibachi");
    
    parent.add(child);
    
    //
    
    parent = new DefaultMutableTreeNode("Grocery Stores");
    
    grandparent.add(parent);
    
    child = new DefaultMutableTreeNode("Real Foods");
    
    parent.add(child);
    
    child = new DefaultMutableTreeNode("Bell Market");
    
    parent.add(child);
    
    
    
    return root;
    
    }
    
    }

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

    Default Re: SwiXML - JTree LazyLoad Expand listener issue

    Do you really write your code all left aligned, with alternate blank lines? Go through this page and learn how to format code for readability: Code Conventions for the Java Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    msambasiva is offline Member
    Join Date
    Jun 2013
    Posts
    18
    Rep Power
    0

    Default Re: SwiXML - JTree LazyLoad Expand listener issue

    Apologies for wrong format. Please find the below code with proper format.
    Please let me know, if you have any comments on this.

    Java Code:
    package com.oracle.appsfdoc.fusion.sos;
    
    import javax.swing.JTree;
    import javax.swing.event.TreeExpansionEvent;
    import javax.swing.event.TreeExpansionListener;
    import javax.swing.event.TreeWillExpandListener;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeNode;
    
    public class LazyLoadDemo extends DefaultTreeModel
                                         implements TreeExpansionListener, 
                                         TreeWillExpandListener {
    
        JTree tree;
        final TreeNode root;
    
        public LazyLoadDemo() {
            super(new DefaultMutableTreeNode("ROOT"));
            System.out.println("LazyLoadDemo");
            root = (DefaultMutableTreeNode)super.getRoot();
            createNodes(root);
            tree = new JTree((TreeNode)root);
            //tree.addTreeExpansionListener(this);
            //tree.addTreeWillExpandListener(this);
            System.out.println("BEFORE HANDLER");
            tree.addTreeExpansionListener(new TreeExpansionListener() {
                    public void treeCollapsed(TreeExpansionEvent e) {
                        System.out.println("Node collapsed at " + e.getPath() +
                                           "\n");
                    }
    
                    public void treeExpanded(TreeExpansionEvent e) {
                        System.out.println("Node expanded at " + e.getPath() +
                                           "\n");
                    }
                });
            System.out.println("AFTER HANDLER");
        }
    
        private void treeForumReviewTreeExpanded(javax.swing.event.TreeExpansionEvent evt) {
            System.out.println("treeForumReviewTreeExpanded");
        }
    
        private TreeNode createNodes(TreeNode root) {
            DefaultMutableTreeNode grandparent;
            DefaultMutableTreeNode parent;
            DefaultMutableTreeNode child;
            DefaultMutableTreeNode temp = (DefaultMutableTreeNode)root;
            root = new DefaultMutableTreeNode("San Francisco");
            grandparent = new DefaultMutableTreeNode("Potrero Hill");
            temp.add(grandparent);
            parent = new DefaultMutableTreeNode("Restaurants");
            grandparent.add(parent);
            child = new DefaultMutableTreeNode("Thai Barbeque");
            parent.add(child);
            child = new DefaultMutableTreeNode("Goat Hill Pizza");
            parent.add(child);
            parent = new DefaultMutableTreeNode("Grocery Stores");
            grandparent.add(parent);
            child = new DefaultMutableTreeNode("Good Life Grocery");
            parent.add(child);
            child = new DefaultMutableTreeNode("Safeway");
            parent.add(child);
            grandparent = new DefaultMutableTreeNode("Noe Valley");
            temp.add(grandparent);
            parent = new DefaultMutableTreeNode("Restaurants");
            grandparent.add(parent);
            child = new DefaultMutableTreeNode("Hamano Sushi");
            parent.add(child);
            child = new DefaultMutableTreeNode("Hahn's Hibachi");
            parent.add(child);
            parent = new DefaultMutableTreeNode("Grocery Stores");
            grandparent.add(parent);
            child = new DefaultMutableTreeNode("Real Foods");
            parent.add(child);
            child = new DefaultMutableTreeNode("Bell Market");
            parent.add(child);
            return root;
       }
        public void treeWillCollapse(TreeExpansionEvent e) {
            System.out.println("treeWillCollapse");
        }
    
        // Required by TreeExpansionListener interface.
        public void treeExpanded(TreeExpansionEvent e) {
            System.out.println("treeExpanded");
        }
    
        // Required by TreeExpansionListener interface.
        public void treeCollapsed(TreeExpansionEvent e) {
            System.out.println("treeCollapsed");
        }
        public void treeWillExpand(TreeExpansionEvent event) {
            System.out.println("treeWillExpand");
        }
    }

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

    Default Re: SwiXML - JTree LazyLoad Expand listener issue

    The only listener added to the tree is the anonymous inner class (lines 27 to 37). Are the events of that anonymous class called? The listener methods in the LazyLoadDemo won't be called automagically as it's not added to any tree as a listener.

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that we can compile and run to see your problem for ourselves.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Applet Expand Collpse Help Required
    By sarfrazasghar in forum Java Applets
    Replies: 0
    Last Post: 11-07-2012, 09:44 AM
  2. Expand & Shrink Buttons
    By umaza in forum AWT / Swing
    Replies: 1
    Last Post: 10-31-2012, 05:22 AM
  3. Compress/Expand data visualization
    By susieferrari in forum JavaFX
    Replies: 4
    Last Post: 07-23-2012, 11:55 AM
  4. How to expand the JPanels dynamically?...
    By Vin in forum New To Java
    Replies: 6
    Last Post: 01-27-2010, 01:58 PM
  5. Move JTree item to another JTree.
    By Melki in forum AWT / Swing
    Replies: 8
    Last Post: 07-09-2009, 12:59 PM

Tags for this Thread

Posting Permissions

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