Window decorations: title bar was not hidden if window is in full-screen mode (issue #212)

This commit is contained in:
Karl Tauber
2020-11-18 23:31:04 +01:00
parent 59879f493e
commit d923c8df81
6 changed files with 51 additions and 5 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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(

View File

@@ -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();

View File

@@ -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;

View File

@@ -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:"