From 150bab0b57aa8b685990ee9166b5318cbb366900 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:19:58 +0100 Subject: [PATCH 1/7] Table: do not select text in cell editor when it gets focus (when `JTable.surrendersFocusOnKeystroke` is `true`) and `TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always` (issue #395) (cherry picked from commit f8b9f4c1fac751a31a0631d22d28ffd3c71137ef) --- CHANGELOG.md | 10 ++++++++++ .../main/java/com/formdev/flatlaf/ui/FlatCaret.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f30a1198..ea9bc231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ FlatLaf Change Log ================== +## 1.6.2 + +#### Fixed bugs + +- Table: Do not select text in cell editor when it gets focus (when + `JTable.surrendersFocusOnKeystroke` is `true`) and + `TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`. + (issue #395) + + ## 1.6.1 #### Fixed bugs diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCaret.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCaret.java index 83a5aac3..4e4a2cee 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCaret.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCaret.java @@ -108,7 +108,7 @@ public class FlatCaret protected void selectAllOnFocusGained() { JTextComponent c = getComponent(); Document doc = c.getDocument(); - if( doc == null || !c.isEnabled() || !c.isEditable() ) + if( doc == null || !c.isEnabled() || !c.isEditable() || FlatUIUtils.isCellEditor( c ) ) return; Object selectAllOnFocusPolicy = c.getClientProperty( SELECT_ALL_ON_FOCUS_POLICY ); From 0b6df8be1c3fe3be0103a5f149afcbed065c41f8 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:26:09 +0100 Subject: [PATCH 2/7] ComboBox (not editable): fixed background painted outside of border if round edges are enabled (similar to issue #382; regression since fixing #330 in FlatLaf 1.4) (cherry picked from commit 02f32396697135d139a6728b041b38221c485f7c) --- CHANGELOG.md | 5 ++++- .../com/formdev/flatlaf/ui/FlatComboBoxUI.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea9bc231..31d67472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ FlatLaf Change Log #### Fixed bugs +- ComboBox (not editable): Fixed background painted outside of border if round + edges are enabled (client property `JComponent.roundRect` is `true`). (similar + to issue #382; regression since fixing #330 in FlatLaf 1.4) - Table: Do not select text in cell editor when it gets focus (when `JTable.surrendersFocusOnKeystroke` is `true`) and `TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`. @@ -43,7 +46,7 @@ FlatLaf Change Log - ComboBox (editable): Fixed wrong border of internal text field under special circumstances. - Spinner: Fixed painting of border corners on left side. (issue #382; - regression since FlatLaf 1.4) + regression since fixing #330 in FlatLaf 1.4) - TableHeader: Do not show resize cursor for last column if resizing last column is not possible because auto resize mode of table is not off. (issue #332) - TableHeader: Fixed missing trailing vertical separator line if used in upper diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 392efd52..759744b4 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -482,6 +482,22 @@ public class FlatComboBoxUI @Override @SuppressWarnings( "unchecked" ) public void paintCurrentValue( Graphics g, Rectangle bounds, boolean hasFocus ) { + // apply clipping using rounded rectangle to avoid that renderer paints + // outside of border if combobox uses larger arc for edges + // (e.g. FlatClientProperties.COMPONENT_ROUND_RECT is true) + FlatBorder border = FlatUIUtils.getOutsideFlatBorder( comboBox ); + if( border != null ) { + int clipArc = border.getArc( comboBox ) - (border.getLineWidth( comboBox ) * 2); + if( clipArc > 0 ) { + int x = bounds.x; + int width = bounds.width + bounds.height; + if( !comboBox.getComponentOrientation().isLeftToRight() ) + x -= bounds.height; + ((Graphics2D)g).clip( FlatUIUtils.createComponentRectangle( + x, bounds.y, width, bounds.height, scale( (float) clipArc ) ) ); + } + } + paddingBorder.uninstall(); ListCellRenderer renderer = comboBox.getRenderer(); From a97076ead58e9bff37a6c11e734764b4d280237f Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:30:10 +0100 Subject: [PATCH 3/7] ComboBox: fix NPE in CellPaddingBorder.install() (issue #408) (cherry picked from commit d48b98f58235081aad8a0a34cd7c277430c31278) --- CHANGELOG.md | 2 ++ .../src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31d67472..75479a88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ FlatLaf Change Log - ComboBox (not editable): Fixed background painted outside of border if round edges are enabled (client property `JComponent.roundRect` is `true`). (similar to issue #382; regression since fixing #330 in FlatLaf 1.4) +- ComboBox: Fixed `NullPointerException`, which may occur under special + circumstances. (issue #408) - Table: Do not select text in cell editor when it gets focus (when `JTable.surrendersFocusOnKeystroke` is `true`) and `TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`. diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 759744b4..d6fef81f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -835,7 +835,7 @@ public class FlatComboBoxUI // remember old border and replace it rendererBorder = jc.getBorder(); - rendererComponent.setBorder( this ); + jc.setBorder( this ); } /** From b590f41254a36404e689298727895c9d6231d03c Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:31:14 +0100 Subject: [PATCH 4/7] Linux: fixed NPE when using `java.awt.TrayIcon` (issue #405) (cherry picked from commit 16a769ea615cad41f4342deb385055adaaf5f80d) --- CHANGELOG.md | 1 + flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75479a88..ee7b8f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ FlatLaf Change Log `JTable.surrendersFocusOnKeystroke` is `true`) and `TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`. (issue #395) +- Linux: Fixed NPE when using `java.awt.TrayIcon`. (issue #405) ## 1.6.1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 9ff1ff0a..120f5ab5 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -264,6 +264,12 @@ public abstract class FlatLaf } }; Toolkit toolkit = Toolkit.getDefaultToolkit(); + + // make sure that AWT desktop properties are initialized (on Linux) + // before invoking toolkit.addPropertyChangeListener() + // https://github.com/JFormDesigner/FlatLaf/issues/405#issuecomment-960242342 + toolkit.getDesktopProperty( "dummy" ); + toolkit.addPropertyChangeListener( desktopPropertyName, desktopPropertyListener ); if( desktopPropertyName2 != null ) toolkit.addPropertyChangeListener( desktopPropertyName2, desktopPropertyListener ); From a284b69a1e75df82128b11e44863200e67303d92 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:35:16 +0100 Subject: [PATCH 5/7] FileChooser: workaround for crash on Windows with Java 17 32bit (issue #403) (cherry picked from commits 44d8545c09f84257b171057343287fd6cd752402 and 33b25c11294ab71297f9b66b1f0a19b84d9f66a2) --- CHANGELOG.md | 2 ++ .../com/formdev/flatlaf/ui/FlatFileChooserUI.java | 12 ++++++++++-- .../java/com/formdev/flatlaf/util/SystemInfo.java | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee7b8f26..abd19639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ FlatLaf Change Log `TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`. (issue #395) - Linux: Fixed NPE when using `java.awt.TrayIcon`. (issue #405) +- FileChooser: Workaround for crash on Windows with Java 17 32-bit (disabled + Windows icons). Java 17 64-bit is not affected. (issue #403) ## 1.6.1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java index 061f0c75..9ed9e909 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java @@ -262,12 +262,20 @@ public class FlatFileChooserUI @Override public FileView getFileView( JFileChooser fc ) { - return fileView; + return doNotUseSystemIcons() ? super.getFileView( fc ) : fileView; } @Override public void clearIconCache() { - fileView.clearIconCache(); + if( doNotUseSystemIcons() ) + super.clearIconCache(); + else + fileView.clearIconCache(); + } + + private boolean doNotUseSystemIcons() { + // Java 17 32bit craches on Windows when using system icons + return SystemInfo.isWindows && SystemInfo.isJava_17_orLater && !SystemInfo.isX86_64; } //---- class FlatFileView ------------------------------------------------- diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java index 305d4ed6..eceecf9b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java @@ -46,6 +46,7 @@ public class SystemInfo public static final boolean isJava_9_orLater; public static final boolean isJava_11_orLater; public static final boolean isJava_15_orLater; + /** @since 2 */ public static final boolean isJava_17_orLater; // Java VMs public static final boolean isJetBrainsJVM; @@ -82,6 +83,7 @@ public class SystemInfo isJava_9_orLater = (javaVersion >= toVersion( 9, 0, 0, 0 )); isJava_11_orLater = (javaVersion >= toVersion( 11, 0, 0, 0 )); isJava_15_orLater = (javaVersion >= toVersion( 15, 0, 0, 0 )); + isJava_17_orLater = (javaVersion >= toVersion( 17, 0, 0, 0 )); // Java VMs isJetBrainsJVM = System.getProperty( "java.vm.vendor", "Unknown" ) From ab320684f5e3b27b169894995a95508e40a0fc5f Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:35:51 +0100 Subject: [PATCH 6/7] Native window decorations: fixed layout loop (issue #420) (cherry picked from commit d3355eda659af232bb22db7108f1c7340cc7d681) --- CHANGELOG.md | 2 ++ .../src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abd19639..fee209ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ FlatLaf Change Log - Linux: Fixed NPE when using `java.awt.TrayIcon`. (issue #405) - FileChooser: Workaround for crash on Windows with Java 17 32-bit (disabled Windows icons). Java 17 64-bit is not affected. (issue #403) +- Native window decorations: Fixed layout loop, which may occur under special + circumstances and slows down the application. (issue #420) ## 1.6.1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index 207b05b2..378f0bb9 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java @@ -508,7 +508,7 @@ public class FlatTitlePane protected void menuBarLayouted() { updateNativeTitleBarHeightAndHitTestSpotsLater(); - revalidate(); + doLayout(); } /*debug From 95a15c3cf803420f02567e770432b2f99e4e67f3 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:45:50 +0100 Subject: [PATCH 7/7] release 1.6.2 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index b46629d7..d1401962 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ * limitations under the License. */ -val releaseVersion = "1.6.1" +val releaseVersion = "1.6.2" val developmentVersion = "2.0-SNAPSHOT" version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion