Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

JTree Keyboard Traversal On Mac OS X #113

Open
mochaman opened this issue Mar 4, 2013 · 0 comments
Open

JTree Keyboard Traversal On Mac OS X #113

mochaman opened this issue Mar 4, 2013 · 0 comments

Comments

@mochaman
Copy link

mochaman commented Mar 4, 2013

When a child node is selected in a JTree, the left arrow key should select the parent node, another press of the left arrow should collapse the parent, etc. This doesn't work in Insubstantial and makes navigating a tree with the keyboard very difficult. I only see this problem on Mac OS X (both Oracle and Apple JVMs).

I worked around it in my project by adding the following code to my JTree subclass:

InputMap im = this.getInputMap();
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "selectParent");

It's possible other navigation keys are failing however this is the one I need/notice.

Quick JTree Example:

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.Hashtable;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.UIManager;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteGlassLookAndFeel;

public class TreeTest {
public static void main(String[] args) {

    Runnable r = new Runnable() {

        public void run() {
            try {
                UIManager.setLookAndFeel(new SubstanceGraphiteGlassLookAndFeel());
            } catch (Exception e) {
                e.printStackTrace();
            }

            JFrame jf = new JFrame("JTree");
            jf.getContentPane().setLayout(new BorderLayout());
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            Hashtable data = new Hashtable();
            String[] nodes = {"Child 1", "Child 2", "Child 3"};
            data.put("Parent Node", nodes);

            JTree tree = new JTree(data);

            jf.getContentPane().add(tree, BorderLayout.CENTER);

            jf.setSize(400,350);
            jf.setVisible(true);
        }
    };
    EventQueue.invokeLater(r);
}

}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant