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,9 +713,11 @@ debug*/
if( r != null ) if( r != null )
hitTestSpots.add( r ); hitTestSpots.add( r );
JMenuBar menuBar = rootPane.getJMenuBar();
if( hasVisibleEmbeddedMenuBar( menuBar ) ) {
r = getNativeHitTestSpot( menuBarPlaceholder ); r = getNativeHitTestSpot( menuBarPlaceholder );
if( r != null ) { if( r != null ) {
Component horizontalGlue = findHorizontalGlue( rootPane.getJMenuBar() ); Component horizontalGlue = findHorizontalGlue( menuBar );
if( horizontalGlue != null ) { if( horizontalGlue != null ) {
// If menu bar is embedded and contains a horizontal glue component, // If menu bar is embedded and contains a horizontal glue component,
// then split the hit test spot into two spots so that // then split the hit test spot into two spots so that
@@ -736,6 +741,7 @@ debug*/
hitTestSpots.add( r ); hitTestSpots.add( r );
} }
}
FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots, appIconBounds ); FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots, appIconBounds );