mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 23:37:13 -06:00
Window decorations: embedded menu bar did not always respond to mouse events after adding menus and when running in JetBrains Runtime (issue #151)
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
FlatLaf Change Log
|
FlatLaf Change Log
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- Custom window decorations: Embedded menu bar did not always respond to mouse
|
||||||
|
events after adding menus and when running in JetBrains Runtime. (issue #151)
|
||||||
|
|
||||||
|
|
||||||
## 0.39
|
## 0.39
|
||||||
|
|
||||||
#### New features
|
#### New features
|
||||||
|
|||||||
@@ -304,6 +304,9 @@ public class FlatRootPaneUI
|
|||||||
Container contentPane = rootPane.getContentPane();
|
Container contentPane = rootPane.getContentPane();
|
||||||
if( contentPane != null )
|
if( contentPane != null )
|
||||||
contentPane.setBounds( 0, nextY, width, Math.max( height - nextY, 0 ) );
|
contentPane.setBounds( 0, nextY, width, Math.max( height - nextY, 0 ) );
|
||||||
|
|
||||||
|
if( titlePane != null )
|
||||||
|
titlePane.menuBarLayouted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -391,6 +391,12 @@ public class FlatTitlePane
|
|||||||
return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) );
|
return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Insets getMenuBarMargins() {
|
||||||
|
return getComponentOrientation().isLeftToRight()
|
||||||
|
? menuBarMargins
|
||||||
|
: new Insets( menuBarMargins.top, menuBarMargins.right, menuBarMargins.bottom, menuBarMargins.left );
|
||||||
|
}
|
||||||
|
|
||||||
protected void menuBarChanged() {
|
protected void menuBarChanged() {
|
||||||
menuBarPlaceholder.invalidate();
|
menuBarPlaceholder.invalidate();
|
||||||
|
|
||||||
@@ -400,12 +406,27 @@ public class FlatTitlePane
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Insets getMenuBarMargins() {
|
protected void menuBarLayouted() {
|
||||||
return getComponentOrientation().isLeftToRight()
|
updateJBRHitTestSpotsAndTitleBarHeightLater();
|
||||||
? menuBarMargins
|
|
||||||
: new Insets( menuBarMargins.top, menuBarMargins.right, menuBarMargins.bottom, menuBarMargins.left );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*debug
|
||||||
|
@Override
|
||||||
|
public void paint( Graphics g ) {
|
||||||
|
super.paint( g );
|
||||||
|
|
||||||
|
if( debugTitleBarHeight > 0 ) {
|
||||||
|
g.setColor( Color.green );
|
||||||
|
g.drawLine( 0, debugTitleBarHeight, getWidth(), debugTitleBarHeight );
|
||||||
|
}
|
||||||
|
if( debugHitTestSpots != null ) {
|
||||||
|
g.setColor( Color.blue );
|
||||||
|
for( Rectangle r : debugHitTestSpots )
|
||||||
|
g.drawRect( r.x, r.y, r.width, r.height );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent( Graphics g ) {
|
protected void paintComponent( Graphics g ) {
|
||||||
g.setColor( getBackground() );
|
g.setColor( getBackground() );
|
||||||
@@ -583,6 +604,12 @@ public class FlatTitlePane
|
|||||||
titleBarHeight--;
|
titleBarHeight--;
|
||||||
|
|
||||||
JBRCustomDecorations.setHitTestSpotsAndTitleBarHeight( window, hitTestSpots, titleBarHeight );
|
JBRCustomDecorations.setHitTestSpotsAndTitleBarHeight( window, hitTestSpots, titleBarHeight );
|
||||||
|
|
||||||
|
/*debug
|
||||||
|
debugHitTestSpots = hitTestSpots;
|
||||||
|
debugTitleBarHeight = titleBarHeight;
|
||||||
|
repaint();
|
||||||
|
debug*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addJBRHitTestSpot( JComponent c, boolean subtractMenuBarMargins, List<Rectangle> hitTestSpots ) {
|
protected void addJBRHitTestSpot( JComponent c, boolean subtractMenuBarMargins, List<Rectangle> hitTestSpots ) {
|
||||||
@@ -599,6 +626,11 @@ public class FlatTitlePane
|
|||||||
hitTestSpots.add( r );
|
hitTestSpots.add( r );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*debug
|
||||||
|
private List<Rectangle> debugHitTestSpots;
|
||||||
|
private int debugTitleBarHeight;
|
||||||
|
debug*/
|
||||||
|
|
||||||
//---- class TitlePaneBorder ----------------------------------------------
|
//---- class TitlePaneBorder ----------------------------------------------
|
||||||
|
|
||||||
protected class FlatTitlePaneBorder
|
protected class FlatTitlePaneBorder
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.awt.event.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
@@ -117,6 +118,32 @@ public class FlatWindowDecorationsTest
|
|||||||
rootPane.putClientProperty( FlatClientProperties.MENU_BAR_EMBEDDED, menuBarEmbeddedCheckBox.isSelected() );
|
rootPane.putClientProperty( FlatClientProperties.MENU_BAR_EMBEDDED, menuBarEmbeddedCheckBox.isSelected() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMenu() {
|
||||||
|
JMenu menu = new JMenu( "Hello" );
|
||||||
|
menu.add( new JMenuItem( "world" ) );
|
||||||
|
menuBar.add( menu );
|
||||||
|
menuBar.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeMenu() {
|
||||||
|
int menuCount = menuBar.getMenuCount();
|
||||||
|
if( menuCount <= 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
menuBar.remove( menuCount - 1 );
|
||||||
|
menuBar.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeMenu() {
|
||||||
|
int menuCount = menuBar.getMenuCount();
|
||||||
|
if( menuCount <= 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int len = new Random().nextInt( 20 );
|
||||||
|
String text = "1234567890abcdefghij".substring( 0, len + 1 );
|
||||||
|
menuBar.getMenu( menuCount - 1 ).setText( text );
|
||||||
|
}
|
||||||
|
|
||||||
private void resizableChanged() {
|
private void resizableChanged() {
|
||||||
Window window = SwingUtilities.windowForComponent( this );
|
Window window = SwingUtilities.windowForComponent( this );
|
||||||
if( window instanceof Frame )
|
if( window instanceof Frame )
|
||||||
@@ -218,6 +245,9 @@ public class FlatWindowDecorationsTest
|
|||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||||
menuBarCheckBox = new JCheckBox();
|
menuBarCheckBox = new JCheckBox();
|
||||||
|
JButton addMenuButton = new JButton();
|
||||||
|
JButton removeMenuButton = new JButton();
|
||||||
|
JButton changeMenuButton = new JButton();
|
||||||
menuBarEmbeddedCheckBox = new JCheckBox();
|
menuBarEmbeddedCheckBox = new JCheckBox();
|
||||||
resizableCheckBox = new JCheckBox();
|
resizableCheckBox = new JCheckBox();
|
||||||
maximizedBoundsCheckBox = new JCheckBox();
|
maximizedBoundsCheckBox = new JCheckBox();
|
||||||
@@ -271,7 +301,7 @@ public class FlatWindowDecorationsTest
|
|||||||
"ltr,insets dialog,hidemode 3",
|
"ltr,insets dialog,hidemode 3",
|
||||||
// columns
|
// columns
|
||||||
"[left]para" +
|
"[left]para" +
|
||||||
"[fill]",
|
"[left]",
|
||||||
// rows
|
// rows
|
||||||
"para[]0" +
|
"para[]0" +
|
||||||
"[]0" +
|
"[]0" +
|
||||||
@@ -287,6 +317,21 @@ public class FlatWindowDecorationsTest
|
|||||||
menuBarCheckBox.addActionListener(e -> menuBarChanged());
|
menuBarCheckBox.addActionListener(e -> menuBarChanged());
|
||||||
add(menuBarCheckBox, "cell 0 0");
|
add(menuBarCheckBox, "cell 0 0");
|
||||||
|
|
||||||
|
//---- addMenuButton ----
|
||||||
|
addMenuButton.setText("Add menu");
|
||||||
|
addMenuButton.addActionListener(e -> addMenu());
|
||||||
|
add(addMenuButton, "cell 1 0 1 2,align left top,grow 0 0");
|
||||||
|
|
||||||
|
//---- removeMenuButton ----
|
||||||
|
removeMenuButton.setText("Remove menu");
|
||||||
|
removeMenuButton.addActionListener(e -> removeMenu());
|
||||||
|
add(removeMenuButton, "cell 1 0 1 2,align left top,grow 0 0");
|
||||||
|
|
||||||
|
//---- changeMenuButton ----
|
||||||
|
changeMenuButton.setText("Change menu");
|
||||||
|
changeMenuButton.addActionListener(e -> changeMenu());
|
||||||
|
add(changeMenuButton, "cell 1 0 1 2,align left top,grow 0 0");
|
||||||
|
|
||||||
//---- menuBarEmbeddedCheckBox ----
|
//---- menuBarEmbeddedCheckBox ----
|
||||||
menuBarEmbeddedCheckBox.setText("embedded menu bar");
|
menuBarEmbeddedCheckBox.setText("embedded menu bar");
|
||||||
menuBarEmbeddedCheckBox.setSelected(true);
|
menuBarEmbeddedCheckBox.setSelected(true);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "7.0.2.0.298" Java: "13.0.2" encoding: "UTF-8"
|
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -8,7 +8,7 @@ new FormModel {
|
|||||||
}
|
}
|
||||||
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
|
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
|
||||||
"$columnConstraints": "[left]para[fill]"
|
"$columnConstraints": "[left]para[left]"
|
||||||
"$rowConstraints": "para[]0[]0[]0[][][top][]"
|
"$rowConstraints": "para[]0[]0[]0[][][top][]"
|
||||||
} ) {
|
} ) {
|
||||||
name: "this"
|
name: "this"
|
||||||
@@ -23,6 +23,27 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 0"
|
"value": "cell 0 0"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "addMenuButton"
|
||||||
|
"text": "Add menu"
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "addMenu", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 0 1 2,align left top,grow 0 0"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "removeMenuButton"
|
||||||
|
"text": "Remove menu"
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "removeMenu", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 0 1 2,align left top,grow 0 0"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
|
name: "changeMenuButton"
|
||||||
|
"text": "Change menu"
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "changeMenu", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 0 1 2,align left top,grow 0 0"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
name: "menuBarEmbeddedCheckBox"
|
name: "menuBarEmbeddedCheckBox"
|
||||||
"text": "embedded menu bar"
|
"text": "embedded menu bar"
|
||||||
@@ -238,7 +259,7 @@ new FormModel {
|
|||||||
} )
|
} )
|
||||||
}, new FormLayoutConstraints( null ) {
|
}, new FormLayoutConstraints( null ) {
|
||||||
"location": new java.awt.Point( 0, 0 )
|
"location": new java.awt.Point( 0, 0 )
|
||||||
"size": new java.awt.Dimension( 450, 380 )
|
"size": new java.awt.Dimension( 550, 380 )
|
||||||
} )
|
} )
|
||||||
add( new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) {
|
add( new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) {
|
||||||
name: "menuBar"
|
name: "menuBar"
|
||||||
|
|||||||
Reference in New Issue
Block a user