mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 14:30:56 +03:00
FlatLaf window decorations: strech iconify/maximize/close buttons to always fill whole title bar height (issue #897)
This commit is contained in:
11
CHANGELOG.md
11
CHANGELOG.md
@@ -11,10 +11,13 @@ FlatLaf Change Log
|
|||||||
`sun.java2d.d3d` and `sun.java2d.noddraw` are not yet set), which disables
|
`sun.java2d.d3d` and `sun.java2d.noddraw` are not yet set), which disables
|
||||||
usage of Windows Direct3D (DirectX) onscreen surfaces. Component rendering
|
usage of Windows Direct3D (DirectX) onscreen surfaces. Component rendering
|
||||||
still uses Direct3D. (issue #887)
|
still uses Direct3D. (issue #887)
|
||||||
- FlatLaf window decorations on Windows: Fixed possible application freeze when
|
- FlatLaf window decorations:
|
||||||
using custom component that overrides `Component.contains(int x, int y)` and
|
- Iconify/maximize/close buttons did not fill whole title bar height, if some
|
||||||
invokes `SwingUtilities.convertPoint()` (or similar) from the overridden
|
custom component in menu bar increases title bar height. (issue #897)
|
||||||
method. (issue #878)
|
- Windows: Fixed possible application freeze when using custom component that
|
||||||
|
overrides `Component.contains(int x, int y)` and invokes
|
||||||
|
`SwingUtilities.convertPoint()` (or similar) from the overridden method.
|
||||||
|
(issue #878)
|
||||||
- TextComponents: Fixed too fast scrolling in multi-line text components when
|
- TextComponents: Fixed too fast scrolling in multi-line text components when
|
||||||
using touchpads (e.g. on macOS). (issue #892)
|
using touchpads (e.g. on macOS). (issue #892)
|
||||||
- ToolBar: Fixed endless loop if button in Toolbar has focus and is made
|
- ToolBar: Fixed endless loop if button in Toolbar has focus and is made
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public abstract class FlatAbstractIcon
|
|||||||
// g2.setColor( Color.blue );
|
// g2.setColor( Color.blue );
|
||||||
// g2.drawRect( x, y, getIconWidth() - 1, getIconHeight() - 1 );
|
// g2.drawRect( x, y, getIconWidth() - 1, getIconHeight() - 1 );
|
||||||
|
|
||||||
|
paintBackground( c, g2, x, y );
|
||||||
|
|
||||||
g2.translate( x, y );
|
g2.translate( x, y );
|
||||||
UIScale.scaleGraphics( g2 );
|
UIScale.scaleGraphics( g2 );
|
||||||
|
|
||||||
@@ -69,7 +71,11 @@ public abstract class FlatAbstractIcon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void paintIcon( Component c, Graphics2D g2 );
|
/** @since 3.5.2 */
|
||||||
|
protected void paintBackground( Component c, Graphics2D g, int x, int y ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void paintIcon( Component c, Graphics2D g );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIconWidth() {
|
public int getIconWidth() {
|
||||||
|
|||||||
@@ -60,23 +60,24 @@ public abstract class FlatWindowAbstractIcon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintIcon( Component c, Graphics2D g ) {
|
protected void paintIcon( Component c, Graphics2D g ) {
|
||||||
paintBackground( c, g );
|
|
||||||
|
|
||||||
g.setColor( getForeground( c ) );
|
g.setColor( getForeground( c ) );
|
||||||
HiDPIUtils.paintAtScale1x( g, 0, 0, width, height, this::paintIconAt1x );
|
HiDPIUtils.paintAtScale1x( g, 0, 0, width, height, this::paintIconAt1x );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void paintIconAt1x( Graphics2D g, int x, int y, int width, int height, double scaleFactor );
|
protected abstract void paintIconAt1x( Graphics2D g, int x, int y, int width, int height, double scaleFactor );
|
||||||
|
|
||||||
protected void paintBackground( Component c, Graphics2D g ) {
|
/** @since 3.5.2 */
|
||||||
|
@Override
|
||||||
|
protected void paintBackground( Component c, Graphics2D g, int x, int y ) {
|
||||||
Color background = FlatButtonUI.buttonStateColor( c, null, null, null, hoverBackground, pressedBackground );
|
Color background = FlatButtonUI.buttonStateColor( c, null, null, null, hoverBackground, pressedBackground );
|
||||||
if( background != null ) {
|
if( background != null ) {
|
||||||
// disable antialiasing for background rectangle painting to avoid blurry edges when scaled (e.g. at 125% or 175%)
|
// disable antialiasing for background rectangle painting to avoid blurry edges when scaled (e.g. at 125% or 175%)
|
||||||
Object oldHint = g.getRenderingHint( RenderingHints.KEY_ANTIALIASING );
|
Object oldHint = g.getRenderingHint( RenderingHints.KEY_ANTIALIASING );
|
||||||
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
|
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
|
||||||
|
|
||||||
|
// fill background of whole component
|
||||||
g.setColor( FlatUIUtils.deriveColor( background, c.getBackground() ) );
|
g.setColor( FlatUIUtils.deriveColor( background, c.getBackground() ) );
|
||||||
g.fillRect( 0, 0, width, height );
|
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
||||||
|
|
||||||
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, oldHint );
|
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, oldHint );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -395,6 +395,12 @@ public class FlatTitlePane
|
|||||||
// allow the button to shrink if space is rare
|
// allow the button to shrink if space is rare
|
||||||
return new Dimension( UIScale.scale( buttonMinimumWidth ), super.getMinimumSize().height );
|
return new Dimension( UIScale.scale( buttonMinimumWidth ), super.getMinimumSize().height );
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public Dimension getMaximumSize() {
|
||||||
|
// allow the button to fill whole button area height
|
||||||
|
// see also BasicMenuUI.getMaximumSize()
|
||||||
|
return new Dimension( super.getMaximumSize().width, Short.MAX_VALUE );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
button.setFocusable( false );
|
button.setFocusable( false );
|
||||||
button.setContentAreaFilled( false );
|
button.setContentAreaFilled( false );
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ public class FlatWindowDecorationsTest
|
|||||||
|
|
||||||
if( rightCompCheckBox.isSelected() ) {
|
if( rightCompCheckBox.isSelected() ) {
|
||||||
rightStretchCompCheckBox.setSelected( false );
|
rightStretchCompCheckBox.setSelected( false );
|
||||||
|
tallCompCheckBox.setSelected( false );
|
||||||
|
|
||||||
JButton myButton = new JButton( "?" );
|
JButton myButton = new JButton( "?" );
|
||||||
myButton.putClientProperty( "JButton.buttonType", "toolBarButton" );
|
myButton.putClientProperty( "JButton.buttonType", "toolBarButton" );
|
||||||
@@ -207,6 +208,7 @@ public class FlatWindowDecorationsTest
|
|||||||
|
|
||||||
if( rightStretchCompCheckBox.isSelected() ) {
|
if( rightStretchCompCheckBox.isSelected() ) {
|
||||||
rightCompCheckBox.setSelected( false );
|
rightCompCheckBox.setSelected( false );
|
||||||
|
tallCompCheckBox.setSelected( false );
|
||||||
|
|
||||||
menuBar.add( Box.createGlue() );
|
menuBar.add( Box.createGlue() );
|
||||||
menuBar.add( new JProgressBar() );
|
menuBar.add( new JProgressBar() );
|
||||||
@@ -216,6 +218,20 @@ public class FlatWindowDecorationsTest
|
|||||||
menuBar.repaint();
|
menuBar.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tallCompChanged() {
|
||||||
|
removeNonMenusFromMenuBar();
|
||||||
|
|
||||||
|
if( tallCompCheckBox.isSelected() ) {
|
||||||
|
rightCompCheckBox.setSelected( false );
|
||||||
|
rightStretchCompCheckBox.setSelected( false );
|
||||||
|
|
||||||
|
menuBar.add( new JButton( "<html>large<br>button<br>large<br>button</html>" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
menuBar.revalidate();
|
||||||
|
menuBar.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
private void removeNonMenusFromMenuBar() {
|
private void removeNonMenusFromMenuBar() {
|
||||||
Component[] components = menuBar.getComponents();
|
Component[] components = menuBar.getComponents();
|
||||||
for( int i = components.length - 1; i >= 0; i-- ) {
|
for( int i = components.length - 1; i >= 0; i-- ) {
|
||||||
@@ -585,6 +601,7 @@ debug*/
|
|||||||
menuBarVisibleCheckBox = new JCheckBox();
|
menuBarVisibleCheckBox = new JCheckBox();
|
||||||
rightCompCheckBox = new JCheckBox();
|
rightCompCheckBox = new JCheckBox();
|
||||||
rightStretchCompCheckBox = new JCheckBox();
|
rightStretchCompCheckBox = new JCheckBox();
|
||||||
|
tallCompCheckBox = new JCheckBox();
|
||||||
JPanel panel3 = new JPanel();
|
JPanel panel3 = new JPanel();
|
||||||
addMenuButton = new JButton();
|
addMenuButton = new JButton();
|
||||||
addGlueButton = new JButton();
|
addGlueButton = new JButton();
|
||||||
@@ -777,6 +794,7 @@ debug*/
|
|||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
"[]" +
|
"[]" +
|
||||||
|
"[]" +
|
||||||
"[]"));
|
"[]"));
|
||||||
|
|
||||||
//---- menuBarCheckBox ----
|
//---- menuBarCheckBox ----
|
||||||
@@ -806,6 +824,11 @@ debug*/
|
|||||||
rightStretchCompCheckBox.setText("right aligned stretching component");
|
rightStretchCompCheckBox.setText("right aligned stretching component");
|
||||||
rightStretchCompCheckBox.addActionListener(e -> rightStretchCompChanged());
|
rightStretchCompCheckBox.addActionListener(e -> rightStretchCompChanged());
|
||||||
panel6.add(rightStretchCompCheckBox, "cell 0 4");
|
panel6.add(rightStretchCompCheckBox, "cell 0 4");
|
||||||
|
|
||||||
|
//---- tallCompCheckBox ----
|
||||||
|
tallCompCheckBox.setText("tall component");
|
||||||
|
tallCompCheckBox.addActionListener(e -> tallCompChanged());
|
||||||
|
panel6.add(tallCompCheckBox, "cell 0 5");
|
||||||
}
|
}
|
||||||
add(panel6, "cell 2 0");
|
add(panel6, "cell 2 0");
|
||||||
|
|
||||||
@@ -1254,6 +1277,7 @@ debug*/
|
|||||||
private JCheckBox menuBarVisibleCheckBox;
|
private JCheckBox menuBarVisibleCheckBox;
|
||||||
private JCheckBox rightCompCheckBox;
|
private JCheckBox rightCompCheckBox;
|
||||||
private JCheckBox rightStretchCompCheckBox;
|
private JCheckBox rightStretchCompCheckBox;
|
||||||
|
private JCheckBox tallCompCheckBox;
|
||||||
private JButton addMenuButton;
|
private JButton addMenuButton;
|
||||||
private JButton addGlueButton;
|
private JButton addGlueButton;
|
||||||
private JButton addCaptionButton;
|
private JButton addCaptionButton;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "8.2.1.0.348" Java: "21.0.1" encoding: "UTF-8"
|
JFDML JFormDesigner: "8.2.3.0.386" Java: "21" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -166,7 +166,7 @@ new FormModel {
|
|||||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "ltr,hidemode 3,gap 0 0"
|
"$layoutConstraints": "ltr,hidemode 3,gap 0 0"
|
||||||
"$columnConstraints": "[left]"
|
"$columnConstraints": "[left]"
|
||||||
"$rowConstraints": "[][][][][]"
|
"$rowConstraints": "[][][][][][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "panel6"
|
name: "panel6"
|
||||||
"border": new javax.swing.border.TitledBorder( "Menu Bar" )
|
"border": new javax.swing.border.TitledBorder( "Menu Bar" )
|
||||||
@@ -223,6 +223,16 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 4"
|
"value": "cell 0 4"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "tallCompCheckBox"
|
||||||
|
"text": "tall component"
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tallCompChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 5"
|
||||||
|
} )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 2 0"
|
"value": "cell 2 0"
|
||||||
} )
|
} )
|
||||||
|
|||||||
Reference in New Issue
Block a user