From 036090a947ef73602cb13463ecc1d58323d9eca6 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 30 Jan 2021 00:37:20 +0100 Subject: [PATCH] Button: fixed behavior of Enter key on focused button on Windows and Linux, which now clicks the focused button (instead of the default button) --- CHANGELOG.md | 8 ++++++++ .../main/java/com/formdev/flatlaf/FlatInputMaps.java | 10 ++++++---- .../main/java/com/formdev/flatlaf/demo/NewDialog.java | 2 ++ .../uidefaults/FlatLightLaf_InputMap_1.8.0_202.txt | 4 +++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aa6132c..97542acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,14 @@ FlatLaf Change Log #### Fixed bugs +- Button: Fixed behavior of Enter key on focused button on Windows + and Linux, which now clicks the focused button (instead of the default + button). + - On Windows, this is a regression in 1.0-rc1. + - On macOS, the Enter key always clicks the default button, which + is the platform behavior. + - On all platforms, the default button can be always clicked with + Ctrl+Enter keys, even if another button is focused. - CheckBox and RadioButton: Fill component background as soon as background color is different to default background color, even if component is not opaque (which is the default). This paints selection if using the component as diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java index 7a463291..ba6ba298 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java @@ -42,10 +42,12 @@ class FlatInputMaps } private static void initBasicInputMaps( UIDefaults defaults ) { - defaults.put( "Button.focusInputMap", new UIDefaults.LazyInputMap( new Object[] { - "SPACE", "pressed", - "released SPACE", "released" - } ) ); + if( SystemInfo.isMacOS ) { + defaults.put( "Button.focusInputMap", new UIDefaults.LazyInputMap( new Object[] { + "SPACE", "pressed", + "released SPACE", "released" + } ) ); + } modifyInputMap( defaults, "ComboBox.ancestorInputMap", "SPACE", "spacePopup", diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/NewDialog.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/NewDialog.java index 3ec5c270..70bcf124 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/NewDialog.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/NewDialog.java @@ -44,10 +44,12 @@ class NewDialog } private void okActionPerformed() { + System.out.println( "ok" ); dispose(); } private void cancelActionPerformed() { + System.out.println( "cancel" ); dispose(); } diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_InputMap_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_InputMap_1.8.0_202.txt index 02d5e355..a34906f7 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_InputMap_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_InputMap_1.8.0_202.txt @@ -7,8 +7,10 @@ OS Windows 10 #---- Button ---- -Button.focusInputMap [lazy] 2 javax.swing.plaf.InputMapUIResource [UI] +Button.focusInputMap [lazy] 4 javax.swing.plaf.InputMapUIResource [UI] + ENTER pressed SPACE pressed + released ENTER released released SPACE released