mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
show mnemonics if the active window does not have a focused component; ignore invisible components (issue #43)
This commit is contained in:
@@ -36,6 +36,7 @@ import java.util.logging.Logger;
|
|||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
import javax.swing.InputMap;
|
import javax.swing.InputMap;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
@@ -430,15 +431,15 @@ public abstract class FlatLaf
|
|||||||
if( SystemInfo.IS_MAC ) {
|
if( SystemInfo.IS_MAC ) {
|
||||||
// Ctrl+Alt keys must be pressed on Mac
|
// Ctrl+Alt keys must be pressed on Mac
|
||||||
if( keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT )
|
if( keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT )
|
||||||
showMnemonics( e.getID() == KeyEvent.KEY_PRESSED && e.isControlDown() && e.isAltDown() );
|
showMnemonics( e.getID() == KeyEvent.KEY_PRESSED && e.isControlDown() && e.isAltDown(), e.getComponent() );
|
||||||
} else {
|
} else {
|
||||||
// Alt key must be pressed on Windows and Linux
|
// Alt key must be pressed on Windows and Linux
|
||||||
if( keyCode == KeyEvent.VK_ALT )
|
if( keyCode == KeyEvent.VK_ALT )
|
||||||
showMnemonics( e.getID() == KeyEvent.KEY_PRESSED );
|
showMnemonics( e.getID() == KeyEvent.KEY_PRESSED, e.getComponent() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showMnemonics( boolean show ) {
|
private static void showMnemonics( boolean show, Component c ) {
|
||||||
if( show == showMnemonics )
|
if( show == showMnemonics )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -449,13 +450,13 @@ public abstract class FlatLaf
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if( show ) {
|
if( show ) {
|
||||||
// get focus owner
|
// get root pane
|
||||||
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
|
JRootPane rootPane = SwingUtilities.getRootPane( c );
|
||||||
if( focusOwner == null )
|
if( rootPane == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// get focused window
|
// get window
|
||||||
Window window = SwingUtilities.windowForComponent( focusOwner );
|
Window window = SwingUtilities.getWindowAncestor( rootPane );
|
||||||
if( window == null )
|
if( window == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -474,6 +475,9 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
private static void repaintMnemonics( Container container ) {
|
private static void repaintMnemonics( Container container ) {
|
||||||
for( Component c : container.getComponents() ) {
|
for( Component c : container.getComponents() ) {
|
||||||
|
if( !c.isVisible() )
|
||||||
|
continue;
|
||||||
|
|
||||||
if( hasMnemonic( c ) )
|
if( hasMnemonic( c ) )
|
||||||
c.repaint();
|
c.repaint();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user