|
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...
|