Window decorations: Fixed NPE in FlatTitlePane.findHorizontalGlue() (issue #275)

This commit is contained in:
Karl Tauber
2021-03-22 18:47:53 +01:00
parent 9612a81f2e
commit 734f3621f1
2 changed files with 36 additions and 22 deletions

View File

@@ -1,6 +1,14 @@
FlatLaf Change Log FlatLaf Change Log
================== ==================
## 1.2-SNAPSHOT
#### Fixed bugs
- Custom window decorations: Fixed NPE in `FlatTitlePane.findHorizontalGlue()`.
(issue #275)
## 1.1 ## 1.1
#### New features and improvements #### New features and improvements

View File

@@ -460,6 +460,9 @@ public class FlatTitlePane
} }
protected Component findHorizontalGlue( JMenuBar menuBar ) { protected Component findHorizontalGlue( JMenuBar menuBar ) {
if( menuBar == null )
return null;
int count = menuBar.getComponentCount(); int count = menuBar.getComponentCount();
for( int i = count - 1; i >= 0; i-- ) { for( int i = count - 1; i >= 0; i-- ) {
Component c = menuBar.getComponent( i ); Component c = menuBar.getComponent( i );
@@ -710,31 +713,34 @@ debug*/
if( r != null ) if( r != null )
hitTestSpots.add( r ); hitTestSpots.add( r );
r = getNativeHitTestSpot( menuBarPlaceholder ); JMenuBar menuBar = rootPane.getJMenuBar();
if( r != null ) { if( hasVisibleEmbeddedMenuBar( menuBar ) ) {
Component horizontalGlue = findHorizontalGlue( rootPane.getJMenuBar() ); r = getNativeHitTestSpot( menuBarPlaceholder );
if( horizontalGlue != null ) { if( r != null ) {
// If menu bar is embedded and contains a horizontal glue component, Component horizontalGlue = findHorizontalGlue( menuBar );
// then split the hit test spot into two spots so that if( horizontalGlue != null ) {
// the glue component area can used to move the window. // If menu bar is embedded and contains a horizontal glue component,
// then split the hit test spot into two spots so that
// the glue component area can used to move the window.
Point glueLocation = SwingUtilities.convertPoint( horizontalGlue, 0, 0, window ); Point glueLocation = SwingUtilities.convertPoint( horizontalGlue, 0, 0, window );
Rectangle r2; Rectangle r2;
if( getComponentOrientation().isLeftToRight() ) { if( getComponentOrientation().isLeftToRight() ) {
int trailingWidth = (r.x + r.width - HIT_TEST_SPOT_GROW) - glueLocation.x; int trailingWidth = (r.x + r.width - HIT_TEST_SPOT_GROW) - glueLocation.x;
r.width -= trailingWidth; r.width -= trailingWidth;
r2 = new Rectangle( glueLocation.x + horizontalGlue.getWidth(), r.y, trailingWidth, r.height ); r2 = new Rectangle( glueLocation.x + horizontalGlue.getWidth(), r.y, trailingWidth, r.height );
} else { } else {
int leadingWidth = (glueLocation.x + horizontalGlue.getWidth()) - (r.x + HIT_TEST_SPOT_GROW); int leadingWidth = (glueLocation.x + horizontalGlue.getWidth()) - (r.x + HIT_TEST_SPOT_GROW);
r.x += leadingWidth; r.x += leadingWidth;
r.width -= leadingWidth; r.width -= leadingWidth;
r2 = new Rectangle( glueLocation.x -leadingWidth, r.y, leadingWidth, r.height ); r2 = new Rectangle( glueLocation.x -leadingWidth, r.y, leadingWidth, r.height );
}
r2.grow( HIT_TEST_SPOT_GROW, HIT_TEST_SPOT_GROW );
hitTestSpots.add( r2 );
} }
r2.grow( HIT_TEST_SPOT_GROW, HIT_TEST_SPOT_GROW );
hitTestSpots.add( r2 );
}
hitTestSpots.add( r ); hitTestSpots.add( r );
}
} }
FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots, appIconBounds ); FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots, appIconBounds );