Skip to content

Commit

Permalink
Window decorations: fixed missing window top border on Windows 10 in …
Browse files Browse the repository at this point in the history
…"full window content" mode (issue 809)
  • Loading branch information
DevCharly committed Mar 17, 2024
1 parent d26819d commit ca500bb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ FlatLaf Change Log
- TabbedPane: Fixed swapped back and forward scroll buttons when using
`TabbedPane.scrollButtonsPlacement = trailing` (regression in FlatLaf 3.3).
- Extras: `FlatSVGIcon` color filters now support linear gradients. (PR #817)
- Fixed missing window top border on Windows 10 in "full window content" mode.
(issue 809)


## 3.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ protected FlatTitlePane createTitlePane() {
// layer title pane under frame content layer to allow placing menu bar over title pane
protected final static Integer TITLE_PANE_LAYER = JLayeredPane.FRAME_CONTENT_LAYER - 1;
private final static Integer TITLE_PANE_MOUSE_LAYER = JLayeredPane.FRAME_CONTENT_LAYER - 2;
private final static Integer WINDOW_TOP_BORDER_LAYER = Integer.MAX_VALUE;

// for fullWindowContent mode, layer title pane over frame content layer to allow placing title bar buttons over content
/** @since 3.4 */
Expand All @@ -285,11 +286,15 @@ protected void setTitlePane( FlatTitlePane newTitlePane ) {
if( titlePane != null ) {
layeredPane.remove( titlePane );
layeredPane.remove( titlePane.mouseLayer );
if( titlePane.windowTopBorderLayer != null )
layeredPane.remove( titlePane.windowTopBorderLayer );
}

if( newTitlePane != null ) {
layeredPane.add( newTitlePane, getLayerForTitlePane() );
layeredPane.add( newTitlePane.mouseLayer, TITLE_PANE_MOUSE_LAYER );
if( newTitlePane.windowTopBorderLayer != null && newTitlePane.isWindowTopBorderNeeded() && isFullWindowContent( rootPane ) )
layeredPane.add( newTitlePane.windowTopBorderLayer, WINDOW_TOP_BORDER_LAYER );
}

titlePane = newTitlePane;
Expand Down Expand Up @@ -446,6 +451,13 @@ public void propertyChange( PropertyChangeEvent e ) {
case FlatClientProperties.FULL_WINDOW_CONTENT:
if( titlePane != null ) {
rootPane.getLayeredPane().setLayer( titlePane, getLayerForTitlePane() );
if( titlePane.windowTopBorderLayer != null ) {
JLayeredPane layeredPane = rootPane.getLayeredPane();
if( titlePane.isWindowTopBorderNeeded() && isFullWindowContent( rootPane ) )
layeredPane.add( titlePane.windowTopBorderLayer, WINDOW_TOP_BORDER_LAYER );
else
layeredPane.remove( titlePane.windowTopBorderLayer );
}
titlePane.updateIcon();
titlePane.updateVisibility();
titlePane.updateFullWindowContentButtonsBoundsProperty();
Expand Down Expand Up @@ -591,6 +603,12 @@ public void layoutContainer( Container parent ) {
titlePane.setBounds( 0, 0, width, prefHeight );

titlePane.mouseLayer.setBounds( 0, 0, width, prefHeight );
if( titlePane.windowTopBorderLayer != null ) {
boolean show = isFullWindowContent && !titlePane.isWindowMaximized() && !isFullScreen;
if( show )
titlePane.windowTopBorderLayer.setBounds( 0, 0, width, 1 );
titlePane.windowTopBorderLayer.setVisible( show );
}

if( !isFullWindowContent )
nextY += prefHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public class FlatTitlePane
extends JComponent
{
static final String KEY_DEBUG_SHOW_RECTANGLES = "FlatLaf.debug.titlebar.showRectangles";
private static final boolean isWindows_10 = SystemInfo.isWindows_10_orLater && !SystemInfo.isWindows_11_orLater;

/** @since 2.5 */ protected final Font titleFont;
protected final Color activeBackground;
Expand Down Expand Up @@ -166,6 +167,16 @@ public class FlatTitlePane
*/
final JPanel mouseLayer;

/**
* This panel paint a border at the top of the window in fullWindowContent mode,
* if FlatLaf window decorations are enabled.
* Only used on Windows 10.
* <p>
* This panel is not a child of the title pane.
* Instead it is added by FlatRootPaneUI to the layered pane at a layer over all other layers.
*/
final JPanel windowTopBorderLayer;

public FlatTitlePane( JRootPane rootPane ) {
this.rootPane = rootPane;

Expand Down Expand Up @@ -207,6 +218,14 @@ public FlatTitlePane( JRootPane rootPane ) {
mouseLayer.addMouseListener( handler );
mouseLayer.addMouseMotionListener( handler );

if( isWindows_10 && FlatNativeWindowBorder.isSupported() ) {
windowTopBorderLayer = new JPanel();
windowTopBorderLayer.setVisible( false );
windowTopBorderLayer.setOpaque( false );
windowTopBorderLayer.setBorder( FlatUIUtils.nonUIResource( FlatNativeWindowBorder.WindowTopBorder.getInstance() ) );
} else
windowTopBorderLayer = null;

applyComponentOrientation( rootPane.getComponentOrientation() );
}

Expand Down Expand Up @@ -919,6 +938,10 @@ protected boolean hasNativeCustomDecoration() {
return window != null && FlatNativeWindowBorder.hasCustomDecoration( window );
}

boolean isWindowTopBorderNeeded() {
return isWindows_10 && hasNativeCustomDecoration();
}

// used to invoke updateNativeTitleBarHeightAndHitTestSpots() only once from latest invokeLater()
private int laterCounter;

Expand Down Expand Up @@ -1146,7 +1169,7 @@ public Insets getBorderInsets( Component c, Insets insets ) {
} else if( borderColor != null && (rootPane.getJMenuBar() == null || !rootPane.getJMenuBar().isVisible()) )
insets.bottom += UIScale.scale( 1 );

if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized() )
if( isWindowTopBorderNeeded() && !isWindowMaximized() )
insets = FlatUIUtils.addInsets( insets, WindowTopBorder.getInstance().getBorderInsets() );

return insets;
Expand All @@ -1165,7 +1188,7 @@ public void paintBorder( Component c, Graphics g, int x, int y, int width, int h
FlatUIUtils.paintFilledRectangle( g, borderColor, x, y + height - lineHeight, width, lineHeight );
}

if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized() )
if( isWindowTopBorderNeeded() && !isWindowMaximized() && !isFullWindowContent() )
WindowTopBorder.getInstance().paintBorder( c, g, x, y, width, height );
}

Expand Down Expand Up @@ -1329,7 +1352,7 @@ public void windowActivated( WindowEvent e ) {
activeChanged( true );
updateNativeTitleBarHeightAndHitTestSpots();

if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() )
if( isWindowTopBorderNeeded() )
WindowTopBorder.getInstance().repaintBorder( FlatTitlePane.this );

repaintWindowBorder();
Expand All @@ -1340,7 +1363,7 @@ public void windowDeactivated( WindowEvent e ) {
activeChanged( false );
updateNativeTitleBarHeightAndHitTestSpots();

if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() )
if( isWindowTopBorderNeeded() )
WindowTopBorder.getInstance().repaintBorder( FlatTitlePane.this );

repaintWindowBorder();
Expand Down

0 comments on commit ca500bb

Please sign in to comment.