diff --git a/CHANGELOG.md b/CHANGELOG.md index c672da9a..6d31c84c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ FlatLaf Change Log and "Flat Darcula" themes. - TabbedPane: Support per component tab height (set client property `JTabbedPane.tabHeight` to an integer). +- ProgressBar: Support square painting (set client property + `JProgressBar.square` to `true`) and larger height even if no string is + painted (set client property `JProgressBar.largeHeight` to `true`). ## 0.24 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java index 09a84016..98ca89c2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java @@ -93,6 +93,22 @@ public interface FlatClientProperties */ String MINIMUM_HEIGHT = "JComponent.minimumHeight"; + /** + * Specifies whether the progress bar has always the larger height even if no string is painted. + *

+ * Component {@link javax.swing.JProgressBar}
+ * Value type {@link java.lang.Boolean} + */ + String PROGRESS_BAR_LARGE_HEIGHT = "JProgressBar.largeHeight"; + + /** + * Specifies whether the progress bar is paint with square edges. + *

+ * Component {@link javax.swing.JProgressBar}
+ * Value type {@link java.lang.Boolean} + */ + String PROGRESS_BAR_SQUARE = "JProgressBar.square"; + /** * Specifies whether the decrease/increase arrow buttons of a scrollbar are shown. *

diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java index 6fc00936..45d2c0ef 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf.ui; +import static com.formdev.flatlaf.FlatClientProperties.*; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; @@ -23,6 +24,7 @@ import java.awt.Graphics2D; import java.awt.Insets; import java.awt.geom.Area; import java.awt.geom.RoundRectangle2D; +import java.beans.PropertyChangeListener; import javax.swing.JComponent; import javax.swing.JProgressBar; import javax.swing.LookAndFeel; @@ -60,6 +62,8 @@ public class FlatProgressBarUI protected Dimension horizontalSize; protected Dimension verticalSize; + private PropertyChangeListener propertyChangeListener; + public static ComponentUI createUI( JComponent c ) { return new FlatProgressBarUI(); } @@ -75,11 +79,35 @@ public class FlatProgressBarUI verticalSize = UIManager.getDimension( "ProgressBar.verticalSize" ); } + @Override + protected void installListeners() { + super.installListeners(); + + propertyChangeListener = e -> { + switch( e.getPropertyName() ) { + case PROGRESS_BAR_LARGE_HEIGHT: + case PROGRESS_BAR_SQUARE: + progressBar.revalidate(); + progressBar.repaint(); + break; + } + }; + progressBar.addPropertyChangeListener( propertyChangeListener ); + } + + @Override + protected void uninstallListeners() { + super.uninstallListeners(); + + progressBar.removePropertyChangeListener( propertyChangeListener ); + propertyChangeListener = null; + } + @Override public Dimension getPreferredSize( JComponent c ) { Dimension size = super.getPreferredSize( c ); - if( progressBar.isStringPainted() ) { + if( progressBar.isStringPainted() || clientPropertyBoolean( c, PROGRESS_BAR_LARGE_HEIGHT, false ) ) { // recalculate progress height/width to make it smaller Insets insets = progressBar.getInsets(); FontMetrics fm = progressBar.getFontMetrics( progressBar.getFont() ); @@ -122,7 +150,9 @@ public class FlatProgressBarUI return; boolean horizontal = (progressBar.getOrientation() == JProgressBar.HORIZONTAL); - int arc = Math.min( UIScale.scale( this.arc ), horizontal ? height : width ); + int arc = clientPropertyBoolean( c, PROGRESS_BAR_SQUARE, false ) + ? 0 + : Math.min( UIScale.scale( this.arc ), horizontal ? height : width ); FlatUIUtils.setRenderingHints( (Graphics2D) g );