Skip to main content

Select JTreeTable node by typing the node initial value

3 replies [Last post]
elisad
Offline
Joined: 2009-01-27
Points: 0

Hi,

I need to select a tree node in a JXtreeTable by typing the initial of the node value.
Note that this is already feasible in JTree and JXTree.

In the attached example, the tree look as below:

+ restaurants
+ food
+ furniture
+ hotels

If initially I select "restaurants" node then I type "f", I expect that the "food" node will be selected,
If I click on "f" again I expect that "furniture" node will be selected,
clicking "f" again "food" node will be selected and so on

Could you please advise?

[java]

import javax.swing.JFrame;
import javax.swing.UnsupportedLookAndFeelException;
import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;

public class TreeTableTest extends JFrame {
private static final long serialVersionUID = 4342135447890117928L;
public TreeTableTest() {
DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode();
root.add(new DefaultMutableTreeTableNode("restaurants"));
root.add(new DefaultMutableTreeTableNode("food"));
root.add(new DefaultMutableTreeTableNode("furniture"));
root.add(new DefaultMutableTreeTableNode("hotels"));

JXTreeTable treeTable = new JXTreeTable();
treeTable.setTreeTableModel(new DefaultTreeTableModel(root));
treeTable.setEditable(false);
getContentPane().add(treeTable);
setVisible(true);
setSize(400, 400);
}

public static void main(String[] args) {

new TreeTableTest();
}

[/java]

Thank you

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

The problem is that is not really the behavior of a table in Swing. How do you propose we reconcile that?

Karl

elisad
Offline
Joined: 2009-01-27
Points: 0

Hi,
This behavior is needed on the Tree part only of the JXTreeTable.
It is very useful to be able to navigate and select tree nodes by typing the initials

Note that I did a stuf to do that in the JXTreeTable and till now it is working fine, but it'll be better if the solution is included in the JXTreeTable
Thanks

kschaefe
Offline
Joined: 2006-06-08
Points: 0

You can open a feature request and supply that as a patch. I'm still not sure that is the "right" solution for JXTreeTable in general, but it will be easier to evaluate.

Karl