mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-09 08:15:09 +03:00
Menus: fixed missing modifiers flags in ActionEvent (issue #371; regression since FlatLaf 1.3)
This commit is contained in:
@@ -8,6 +8,13 @@ FlatLaf Change Log
|
|||||||
- InternalFrame: Double-click on icon in internal frame title bar now closes the
|
- InternalFrame: Double-click on icon in internal frame title bar now closes the
|
||||||
internal frame. (issue #374)
|
internal frame. (issue #374)
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- Menus: Fixed missing modifiers flags in `ActionEvent` (e.g. `Ctrl` key
|
||||||
|
pressed) when running in Java 9+ on Linux, macOS. Occurs also on Windows in
|
||||||
|
large popup menus that do not fit into the window. (issue #371; regression
|
||||||
|
since FlatLaf 1.3)
|
||||||
|
|
||||||
|
|
||||||
## 1.5
|
## 1.5
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,11 @@ import java.awt.Insets;
|
|||||||
import java.awt.LayoutManager;
|
import java.awt.LayoutManager;
|
||||||
import java.awt.LayoutManager2;
|
import java.awt.LayoutManager2;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.HierarchyEvent;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.HierarchyListener;
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.ComponentListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
@@ -38,6 +40,7 @@ import javax.swing.JLayeredPane;
|
|||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JRootPane;
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.BorderUIResource;
|
import javax.swing.plaf.BorderUIResource;
|
||||||
@@ -81,7 +84,8 @@ public class FlatRootPaneUI
|
|||||||
|
|
||||||
private Object nativeWindowBorderData;
|
private Object nativeWindowBorderData;
|
||||||
private LayoutManager oldLayout;
|
private LayoutManager oldLayout;
|
||||||
private HierarchyListener hierarchyListener;
|
private PropertyChangeListener ancestorListener;
|
||||||
|
private ComponentListener componentListener;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatRootPaneUI();
|
return new FlatRootPaneUI();
|
||||||
@@ -149,16 +153,32 @@ public class FlatRootPaneUI
|
|||||||
// This is very disturbing in dark themes, but hard to notice in light themes.
|
// This is very disturbing in dark themes, but hard to notice in light themes.
|
||||||
// Seems to be a rounding issue when Swing adds dirty region of window
|
// Seems to be a rounding issue when Swing adds dirty region of window
|
||||||
// using RepaintManager.nativeAddDirtyRegion().
|
// using RepaintManager.nativeAddDirtyRegion().
|
||||||
hierarchyListener = e -> {
|
//
|
||||||
if( (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 &&
|
// Note: Not using a HierarchyListener here, which would be much easier,
|
||||||
rootPane.getParent() instanceof Window )
|
// because this causes problems with mouse clicks in heavy-weight popups.
|
||||||
{
|
// Instead, add a listener to the root pane that waits until it is added
|
||||||
// add whole root pane to dirty regions when window is initially shown
|
// to a window, then add a component listener to the window.
|
||||||
rootPane.getParent().repaint( rootPane.getX(), rootPane.getY(),
|
// See: https://github.com/JFormDesigner/FlatLaf/issues/371
|
||||||
rootPane.getWidth(), rootPane.getHeight() );
|
ancestorListener = e -> {
|
||||||
|
Object oldValue = e.getOldValue();
|
||||||
|
Object newValue = e.getNewValue();
|
||||||
|
if( newValue instanceof Window ) {
|
||||||
|
if( componentListener == null ) {
|
||||||
|
componentListener = new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentShown( ComponentEvent e ) {
|
||||||
|
// add whole root pane to dirty regions when window is initially shown
|
||||||
|
root.getParent().repaint( root.getX(), root.getY(), root.getWidth(), root.getHeight() );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
((Window)newValue).addComponentListener( componentListener );
|
||||||
|
} else if( newValue == null && oldValue instanceof Window ) {
|
||||||
|
if( componentListener != null )
|
||||||
|
((Window)oldValue).removeComponentListener( componentListener );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
root.addHierarchyListener( hierarchyListener );
|
root.addPropertyChangeListener( "ancestor", ancestorListener );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +187,14 @@ public class FlatRootPaneUI
|
|||||||
super.uninstallListeners( root );
|
super.uninstallListeners( root );
|
||||||
|
|
||||||
if( SystemInfo.isJava_9_orLater ) {
|
if( SystemInfo.isJava_9_orLater ) {
|
||||||
root.removeHierarchyListener( hierarchyListener );
|
if( componentListener != null ) {
|
||||||
hierarchyListener = null;
|
Window window = SwingUtilities.windowForComponent( root );
|
||||||
|
if( window != null )
|
||||||
|
window.removeComponentListener( componentListener );
|
||||||
|
componentListener = null;
|
||||||
|
}
|
||||||
|
root.removePropertyChangeListener( "ancestor", ancestorListener );
|
||||||
|
ancestorListener = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user