如何在BasicTreeUI上关闭键处理

时间:2022-06-30 12:37:31

BasicTreeUI (in JDK 1.5) handles key events on JTree by navigating to an item on the tree that starts with that letter. What is the most straight forward way to turn that behavior off?

BasicTreeUI(在JDK 1.5中)通过导航到以该字母开头的树上的项来处理JTree上的键事件。什么是最直接的方式来扭转这种行为?

2 个解决方案

#1


I think the most straightforward way is to override the createKeyListener method:

我认为最直接的方法是覆盖createKeyListener方法:

tree.setUI(
        new BasicTreeUI(){
            protected KeyListener createKeyListener(){ return null; }
        }
    );

#2


Don't know much about JTree, but it provides a method you can customize:

不太了解JTree,但它提供了一种可以自定义的方法:

JTree tree = new JTree(...)
{
    public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias)
    {
        return getLeadSelectionPath();
    }
};

#1


I think the most straightforward way is to override the createKeyListener method:

我认为最直接的方法是覆盖createKeyListener方法:

tree.setUI(
        new BasicTreeUI(){
            protected KeyListener createKeyListener(){ return null; }
        }
    );

#2


Don't know much about JTree, but it provides a method you can customize:

不太了解JTree,但它提供了一种可以自定义的方法:

JTree tree = new JTree(...)
{
    public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias)
    {
        return getLeadSelectionPath();
    }
};