diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java index 5d4a7693..a9e4b8a6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java @@ -132,6 +132,14 @@ public interface FlatSystemProperties */ String ANIMATION = "flatlaf.animation"; + /** + * Specifies whether smooth scrolling is enabled. + *
+ * Allowed Values {@code false} and {@code true}
+ * Default {@code true}
+ */
+ String SMOOTH_SCROLLING = "flatlaf.smoothScrolling";
+
/**
* Specifies whether vertical text position is corrected when UI is scaled on HiDPI screens.
*
diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java index 676abfe1..9a5abc2a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java @@ -40,6 +40,7 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollBarUI; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.FlatSystemProperties; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider; @@ -540,6 +541,9 @@ public class FlatScrollBarUI } protected boolean isSmoothScrollingEnabled() { + if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( FlatSystemProperties.SMOOTH_SCROLLING, true ) ) + return false; + // if scroll bar is child of scroll pane, check only client property of scroll pane Container parent = scrollbar.getParent(); JComponent c = (parent instanceof JScrollPane) ? (JScrollPane) parent : scrollbar; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java index 551faaad..bcfb6efb 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java @@ -48,8 +48,10 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollPaneUI; import com.formdev.flatlaf.FlatClientProperties; +import com.formdev.flatlaf.FlatSystemProperties; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI; +import com.formdev.flatlaf.util.Animator; import com.formdev.flatlaf.util.LoggingFacade; /** @@ -160,6 +162,9 @@ public class FlatScrollPaneUI } protected boolean isSmoothScrollingEnabled() { + if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( FlatSystemProperties.SMOOTH_SCROLLING, true ) ) + return false; + Object smoothScrolling = scrollpane.getClientProperty( FlatClientProperties.SCROLL_PANE_SMOOTH_SCROLLING ); if( smoothScrolling instanceof Boolean ) return (Boolean) smoothScrolling; diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java index 5cb20c52..ca9c5795 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java @@ -33,6 +33,7 @@ import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatIntelliJLaf; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLightLaf; +import com.formdev.flatlaf.FlatSystemProperties; import com.formdev.flatlaf.demo.HintManager.Hint; import com.formdev.flatlaf.demo.extras.*; import com.formdev.flatlaf.demo.intellijthemes.*; @@ -266,6 +267,14 @@ class DemoFrame repaint(); } + private void animationChanged() { + boolean enabled = animationMenuItem.isSelected(); + System.setProperty( FlatSystemProperties.ANIMATION, Boolean.toString( enabled ) ); + + smoothScrollingMenuItem.setEnabled( enabled ); + animatedLafChangeMenuItem.setEnabled( enabled ); + } + private void smoothScrollingChanged() { UIManager.put( "ScrollPane.smoothScrolling", smoothScrollingMenuItem.isSelected() ); } @@ -509,6 +518,7 @@ class DemoFrame showTitleBarIconMenuItem = new JCheckBoxMenuItem(); underlineMenuSelectionMenuItem = new JCheckBoxMenuItem(); alwaysShowMnemonicsMenuItem = new JCheckBoxMenuItem(); + animationMenuItem = new JCheckBoxMenuItem(); smoothScrollingMenuItem = new JCheckBoxMenuItem(); animatedLafChangeMenuItem = new JCheckBoxMenuItem(); JMenuItem showHintsMenuItem = new JMenuItem(); @@ -797,6 +807,13 @@ class DemoFrame alwaysShowMnemonicsMenuItem.setText("Always show mnemonics"); alwaysShowMnemonicsMenuItem.addActionListener(e -> alwaysShowMnemonics()); optionsMenu.add(alwaysShowMnemonicsMenuItem); + optionsMenu.addSeparator(); + + //---- animationMenuItem ---- + animationMenuItem.setText("Animation"); + animationMenuItem.setSelected(true); + animationMenuItem.addActionListener(e -> animationChanged()); + optionsMenu.add(animationMenuItem); //---- smoothScrollingMenuItem ---- smoothScrollingMenuItem.setText("Smooth Scrolling"); @@ -992,6 +1009,7 @@ class DemoFrame private JCheckBoxMenuItem showTitleBarIconMenuItem; private JCheckBoxMenuItem underlineMenuSelectionMenuItem; private JCheckBoxMenuItem alwaysShowMnemonicsMenuItem; + private JCheckBoxMenuItem animationMenuItem; private JCheckBoxMenuItem smoothScrollingMenuItem; private JCheckBoxMenuItem animatedLafChangeMenuItem; private JMenuItem aboutMenuItem; diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd index c44f5993..1e5b104a 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd @@ -418,6 +418,18 @@ new FormModel { } addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "alwaysShowMnemonics", false ) ) } ) + add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { + name: "separator9" + } ) + add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { + name: "animationMenuItem" + "text": "Animation" + "selected": true + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "animationChanged", false ) ) + } ) add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { name: "smoothScrollingMenuItem" "text": "Smooth Scrolling" diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/intellijthemes/IJThemesPanel.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/intellijthemes/IJThemesPanel.java index 1af0f05c..0c2561e2 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/intellijthemes/IJThemesPanel.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/intellijthemes/IJThemesPanel.java @@ -25,6 +25,7 @@ import java.awt.Window; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; +import java.beans.Beans; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; @@ -156,6 +157,9 @@ public class IJThemesPanel } private void updateThemesList() { + if( Beans.isDesignTime() ) + return; // disable if running in GUI builder + int filterLightDark = filterComboBox.getSelectedIndex(); boolean showLight = (filterLightDark != 2); boolean showDark = (filterLightDark != 1); diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatAnimatedLafChange.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatAnimatedLafChange.java index b46d26f4..46899a19 100644 --- a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatAnimatedLafChange.java +++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatAnimatedLafChange.java @@ -67,7 +67,7 @@ public class FlatAnimatedLafChange * Invoke before setting new look and feel. */ public static void showSnapshot() { - if( !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) ) + if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) ) return; // stop already running animation @@ -138,7 +138,7 @@ public class FlatAnimatedLafChange * Invoke after updating UI. */ public static void hideSnapshotWithAnimation() { - if( !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) ) + if( !Animator.useAnimation() || !FlatSystemProperties.getBoolean( "flatlaf.animatedLafChange", true ) ) return; if( oldUIsnapshots.isEmpty() )