From d923c8df8170901880ebf9d91739b25bb389606a Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 18 Nov 2020 23:31:04 +0100 Subject: [PATCH] Window decorations: title bar was not hidden if window is in full-screen mode (issue #212) --- CHANGELOG.md | 6 ++++++ .../com/formdev/flatlaf/ui/FlatRootPaneUI.java | 5 +++-- .../java/com/formdev/flatlaf/ui/FlatUIUtils.java | 13 +++++++++++++ .../com/formdev/flatlaf/ui/FlatWindowResizer.java | 8 +++++--- .../flatlaf/testing/FlatWindowDecorationsTest.java | 14 ++++++++++++++ .../flatlaf/testing/FlatWindowDecorationsTest.jfd | 10 ++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3b24fc..f1832ed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ FlatLaf Change Log - JIDE Common Layer: Support `RangeSlider`. (PR #209) +#### Fixed bugs + +- Custom window decorations: Title bar was not hidden if window is in + full-screen mode. (issue #212) + + ## 0.44 #### New features and improvements diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java index 82098cda..c7e89ca7 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java @@ -285,6 +285,7 @@ public class FlatRootPaneUI @Override public void layoutContainer( Container parent ) { JRootPane rootPane = (JRootPane) parent; + boolean isFullScreen = FlatUIUtils.isFullScreen( rootPane ); Insets insets = rootPane.getInsets(); int x = insets.left; @@ -298,7 +299,7 @@ public class FlatRootPaneUI rootPane.getGlassPane().setBounds( x, y, width, height ); int nextY = 0; - if( titlePane != null ) { + if( !isFullScreen && titlePane != null ) { Dimension prefSize = titlePane.getPreferredSize(); titlePane.setBounds( 0, 0, width, prefSize.height ); nextY += prefSize.height; @@ -306,7 +307,7 @@ public class FlatRootPaneUI JMenuBar menuBar = rootPane.getJMenuBar(); if( menuBar != null && menuBar.isVisible() ) { - if( titlePane != null && titlePane.isMenuBarEmbedded() ) { + if( !isFullScreen && titlePane != null && titlePane.isMenuBarEmbedded() ) { titlePane.validate(); menuBar.setBounds( titlePane.getMenuBarBounds() ); } else { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java index 0d8efb20..a43fcad7 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java @@ -23,11 +23,14 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; import java.awt.Insets; import java.awt.KeyboardFocusManager; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.Shape; +import java.awt.Window; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.MouseAdapter; @@ -181,6 +184,16 @@ public class FlatUIUtils keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c ); } + /** + * Returns whether the given component is in a window that is in full-screen mode. + */ + public static boolean isFullScreen( Component c ) { + GraphicsConfiguration gc = c.getGraphicsConfiguration(); + GraphicsDevice gd = (gc != null) ? gc.getDevice() : null; + Window fullScreenWindow = (gd != null) ? gd.getFullScreenWindow() : null; + return (fullScreenWindow != null && fullScreenWindow == SwingUtilities.windowForComponent( c )); + } + public static Boolean isRoundRect( Component c ) { return (c instanceof JComponent) ? FlatClientProperties.clientPropertyBooleanStrict( diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java index cd1c3784..22821b11 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java @@ -256,6 +256,8 @@ public abstract class FlatWindowResizer @Override protected boolean isWindowResizable() { + if( FlatUIUtils.isFullScreen( resizeComp ) ) + return false; if( window instanceof Frame ) return ((Frame)window).isResizable() && (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) == 0; if( window instanceof Dialog ) @@ -429,9 +431,9 @@ public abstract class FlatWindowResizer protected void paintComponent( Graphics g ) { super.paintChildren( g ); - // this is necessary because Dialog.setResizable() does not fire events - if( isDialog() ) - updateVisibility(); + // for dialogs: necessary because Dialog.setResizable() does not fire events + // for frames: necessary because GraphicsDevice.setFullScreenWindow() does not fire events + updateVisibility(); /*debug int width = getWidth(); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java index b513149d..f82312e4 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java @@ -186,6 +186,13 @@ public class FlatWindowDecorationsTest } } + private void fullScreenChanged() { + boolean fullScreen = fullScreenCheckBox.isSelected(); + + GraphicsDevice gd = getGraphicsConfiguration().getDevice(); + gd.setFullScreenWindow( fullScreen ? SwingUtilities.windowForComponent( this ) : null ); + } + private void menuItemActionPerformed(ActionEvent e) { SwingUtilities.invokeLater( () -> { JOptionPane.showMessageDialog( this, e.getActionCommand(), "Menu Item", JOptionPane.PLAIN_MESSAGE ); @@ -263,6 +270,7 @@ public class FlatWindowDecorationsTest resizableCheckBox = new JCheckBox(); maximizedBoundsCheckBox = new JCheckBox(); undecoratedCheckBox = new JCheckBox(); + fullScreenCheckBox = new JCheckBox(); JLabel label1 = new JLabel(); JLabel label2 = new JLabel(); JPanel panel1 = new JPanel(); @@ -372,6 +380,11 @@ public class FlatWindowDecorationsTest undecoratedCheckBox.addActionListener(e -> undecoratedChanged()); add(undecoratedCheckBox, "cell 0 4"); + //---- fullScreenCheckBox ---- + fullScreenCheckBox.setText("full screen"); + fullScreenCheckBox.addActionListener(e -> fullScreenChanged()); + add(fullScreenCheckBox, "cell 1 4"); + //---- label1 ---- label1.setText("Style:"); add(label1, "cell 0 5"); @@ -677,6 +690,7 @@ public class FlatWindowDecorationsTest private JCheckBox resizableCheckBox; private JCheckBox maximizedBoundsCheckBox; private JCheckBox undecoratedCheckBox; + private JCheckBox fullScreenCheckBox; private JRadioButton styleNoneRadioButton; private JRadioButton styleFrameRadioButton; private JRadioButton stylePlainRadioButton; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd index f73e537f..d536cc39 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd @@ -106,6 +106,16 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 4" } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "fullScreenCheckBox" + "text": "full screen" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "fullScreenChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 4" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label1" "text": "Style:"