mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

How to disable the use of SPACEBAR and ENTER in WebSwitch #581

Open mokun opened 4 years ago

mokun commented 4 years ago

When I look inside the constructor of WebSwitch, I found out it automatically make use of SPACEBAR and ENTER for selecting/deselecting the switch.

        final KeyEventRunnable keyEventRunnable = new KeyEventRunnable ()
        {
            @Override
            public void run ( @NotNull final KeyEvent e )
            {
                manualSelection.run ();
            }
        };
        final MouseEventRunnable mouseEventRunnable = new MouseEventRunnable ()
        {
            @Override
            public void run ( @NotNull final MouseEvent e )
            {
                manualSelection.run ();
            }
        };
        onKeyPress ( Hotkey.ENTER, keyEventRunnable );
        onKeyPress ( Hotkey.SPACE, keyEventRunnable );
        onMousePress ( MouseButton.left, mouseEventRunnable );

Is there a way to remove the Key listener on these two ?

Can I register a key of my own choice (e.g. ESC key) for switching ?

Appreciate !

mgarin commented 4 years ago

I've added a separate issue for WebSwitch rework: #582

I'll make use of the Swing ActionMap and InputMap for actions instead of custom listeners, this will allow changing them at will by providing custom KeyStrokes into switch InputMap.