From d756041b065d4b125f5630de5e01acd575e34be3 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 22 Sep 2021 23:40:10 +0200 Subject: [PATCH] Styling: fixed "Illegal reflective access" warning on stdout for BasicMenuItemUI fields when running on Java 9+ --- .../flatlaf/ui/FlatCheckBoxMenuItemUI.java | 13 ++++++++++- .../formdev/flatlaf/ui/FlatMenuItemUI.java | 22 +++++++------------ .../com/formdev/flatlaf/ui/FlatMenuUI.java | 12 +++++++++- .../flatlaf/ui/FlatRadioButtonMenuItemUI.java | 13 ++++++++++- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java index b899d7b3..b84dca91 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf.ui; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.beans.PropertyChangeListener; @@ -117,7 +118,17 @@ public class FlatCheckBoxMenuItemUI // ignore } - return FlatMenuItemUI.applyStyleProperty( this, menuItem, key, value ); + Object oldValue; + switch( key ) { + // BasicMenuItemUI + case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue; + case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue; + case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue; + case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue; + case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue; + } + + return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value ); } /** diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java index 4d85b14b..dd7c849b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java @@ -24,7 +24,6 @@ import java.util.LinkedHashMap; import java.util.Map; import javax.swing.Icon; import javax.swing.JComponent; -import javax.swing.JMenuItem; import javax.swing.LookAndFeel; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuItemUI; @@ -120,22 +119,17 @@ public class FlatMenuItemUI // ignore } - return applyStyleProperty( this, menuItem, key, value ); - } - - static Object applyStyleProperty( BasicMenuItemUI ui, JMenuItem menuItem, String key, Object value ) { + Object oldValue; switch( key ) { // BasicMenuItemUI - case "selectionBackground": - case "selectionForeground": - case "disabledForeground": - case "acceleratorForeground": - case "acceleratorSelectionForeground": - return FlatStylingSupport.applyToField( ui, key, key, value ); - - default: - return FlatStylingSupport.applyToAnnotatedObjectOrComponent( ui, menuItem, key, value ); + case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue; + case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue; + case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue; + case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue; + case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue; } + + return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value ); } /** diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java index edf94112..62d735dc 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java @@ -165,7 +165,17 @@ public class FlatMenuUI // ignore } - return FlatMenuItemUI.applyStyleProperty( this, menuItem, key, value ); + Object oldValue; + switch( key ) { + // BasicMenuItemUI + case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue; + case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue; + case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue; + case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue; + case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue; + } + + return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value ); } /** diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java index 0510ba3b..b326ab89 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf.ui; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.beans.PropertyChangeListener; @@ -117,7 +118,17 @@ public class FlatRadioButtonMenuItemUI // ignore } - return FlatMenuItemUI.applyStyleProperty( this, menuItem, key, value ); + Object oldValue; + switch( key ) { + // BasicMenuItemUI + case "selectionBackground": oldValue = selectionBackground; selectionBackground = (Color) value; return oldValue; + case "selectionForeground": oldValue = selectionForeground; selectionForeground = (Color) value; return oldValue; + case "disabledForeground": oldValue = disabledForeground; disabledForeground = (Color) value; return oldValue; + case "acceleratorForeground": oldValue = acceleratorForeground; acceleratorForeground = (Color) value; return oldValue; + case "acceleratorSelectionForeground": oldValue = acceleratorSelectionForeground; acceleratorSelectionForeground = (Color) value; return oldValue; + } + + return FlatStylingSupport.applyToAnnotatedObjectOrComponent( this, menuItem, key, value ); } /**