Results 1 to 3 of 3
- 01-09-2008, 06:34 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 6
- Rep Power
- 0
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...
- 01-09-2008, 06:54 AM #2
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.
- 01-09-2008, 07:06 AM #3
Member
- Join Date
- Jan 2008
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
add an undo listener to a Jtable
By christina in forum Advanced JavaReplies: 12Last Post: 01-29-2009, 07:47 AM -
No datas in added to arraylist
By Preethi in forum New To JavaReplies: 0Last Post: 02-15-2008, 11:07 AM -
Listener for SWT event
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:04 AM -
how to refresh the table when a new account is added and display instantly
By sravanthi narra in forum SWT / JFaceReplies: 4Last Post: 01-05-2008, 07:39 PM -
Listener collision on game
By cachi in forum Java AppletsReplies: 1Last Post: 08-07-2007, 07:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks