JTree open folder on single click

I have a custom tree that expands JTree and would like the folders to open/close on a single click rather than a double click (per user requirements). Should I do this with a mouse listener and based on the node do something, or is there another way? Also, how can I programatically toggle a folder node opened/closed state?

Thanks!

[345 byte] By [gestes59a] at [2007-10-2 20:27:39]
# 1
Often, the easiest solution is right in front of you. In the JTree, there is a value:protected int toggleClickCount = 2;All I needed to do was change that in my tree to be 1.Sometimes you just need to go in and look at the original Java code.
gestes59a at 2007-7-13 23:10:32 > top of Java-index,Desktop,Core GUI APIs...
# 2

> I have a custom tree that expands JTree and would

> like the folders to open/close on a single click

> rather than a double click (per user requirements).

> Should I do this with a mouse listener and based on

> the node do something, or is there another way? Also,

> how can I programatically toggle a folder node

> opened/closed state?

>

> Thanks!

Here's one way:

someTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

public void valueChanged(TreeSelectionEvent e) {

if (!someTree.isExpanded(someTree.getSelectionModel().getLeadSelectionRow())) {

someTree.expandPath(e.getNewLeadSelectionPath());

}

}

});

Niceguy1a at 2007-7-13 23:10:32 > top of Java-index,Desktop,Core GUI APIs...