File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Tree with Listener not working when added to ScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Tree with Listener not working when added to ScrollPane " Watch "Tree with Listener not working when added to ScrollPane " New topic

Tree with Listener not working when added to ScrollPane

Praveen Kumar Anekalmath

Joined: Feb 26, 2007
Posts: 18
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);

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)
/* if nothing is selected */
if (node == null) return;
/* retrive the node that was selected */
Object nodeInfo = node.getUserObject();
if( nodeInfo.equals(UIProperties.getLocaleText("enterprise")))
if(CommonRightPanel.jPanelRightMain.getComponentCount() > 0)
CommonRightPanel.jPanelRightMain.add(EnterpriseMain.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,

it works fine...But i need scrollPane to be added...
What is the solution for this...Can please anyone help...

I agree. Here's the link:
subject: Tree with Listener not working when added to ScrollPane
jQuery in Action, 3rd edition