Results 1 to 3 of 3
  1. #1
    praveen.kb is offline Member
    Join Date
    Jan 2008
    Posts
    6
    Rep Power
    0

    Angry Tree with Listener not working when added to ScrollPane

    Hi,
    I want to add a scrollpane to tree so that on expansion of the tree, scroll bar comes.I'm using the following code:

    JSscrollPane = new JScrollPane(jTree);
    jPanel.add(scrollPane,BorderLayout.CENTER);

    By doing so,i'm able to see scroll bar when tree expands. But the listener added for tree is not working.Below is the code adding listener:

    jTree.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e)
    {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)
    jTree.getLastSelectedPathComponent(); jTree.setToggleClickCount(1);
    /* if nothing is selected */
    if (node == null) return;
    /* retrive the node that was selected */
    Object nodeInfo = node.getUserObject();
    if(nodeInfo!=null)
    {
    if( nodeInfo.equals(UIProperties.getLocaleText("enterp rise")))
    {
    if(CommonRightPanel.jPanelRightMain.getComponentCo unt() > 0)
    {
    CommonRightPanel.jPanelRightMain.add(EnterpriseMai n.getRightToolBar(),BorderLayout.NORTH);
    CommonRightPanel.jPanelRightMain.add(EnterpriseMai n.getSearchPanel(),BorderLayout.CENTER);
    CommonRightPanel.jPanelRightMain.add(EnterpriseMai n.getSearchDisplayPanel(), BorderLayout.SOUTH);

    }
    }
    }
    }
    });
    As in code above, i'm trying to add some panels in the rightPanel of the window, its not happening but Listener is working fine as i added sysout statement.
    Instead of adding jTree to scrollPane,if i add jTree to jPanel say like this,

    jPanel.add(jTree,BorderLayout.CENTER);
    it works fine...But i need scrollPane to be added...
    What is the solution for this...Can please anyone help...

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    You may have some layout problems. It's hard to tell without seeing how you put things together. When you add/remove/change components in a container you need to tell the container to validate itself. You can do this with the Container method validate or the JComponent method revalidate.
    The TreeSelectionListener will only receive events when the tree selection has changed.

  3. #3
    praveen.kb is offline Member
    Join Date
    Jan 2008
    Posts
    6
    Rep Power
    0

    Smile

    Thank you very much hardwired... It works...
    I tried putting
    CommonRightPanel.jPanelRightMain.validate();
    and it works...
    Thanks to Java Forums

Similar Threads

  1. add an undo listener to a Jtable
    By christina in forum Advanced Java
    Replies: 12
    Last Post: 01-29-2009, 07:47 AM
  2. No datas in added to arraylist
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 02-15-2008, 11:07 AM
  3. Listener for SWT event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 09:04 AM
  4. Replies: 4
    Last Post: 01-05-2008, 07:39 PM
  5. Listener collision on game
    By cachi in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 07:48 AM

Posting Permissions

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