Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tree with Listener not working when added to ScrollPane

 
Praveen Kumar Anekalmath
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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("enterprise")))
{
if(CommonRightPanel.jPanelRightMain.getComponentCount() > 0)
CommonRightPanel.jPanelRightMain.add(EnterpriseMain.getRightToolBar(),BorderLayout.NORTH);
CommonRightPanel.jPanelRightMain.add(EnterpriseMain.getSearchPanel(),BorderLayout.CENTER);
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,

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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic