diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f40cd626..f8722cf06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ FlatLaf Change Log ## Unreleased +- Hide menu mnemonics by default and show them only when Alt key is + pressed. (issue #43) - TabbedPane: In scroll-tab-layout, the cropped line is now hidden. (issue #40) - Tree: UI default value `Tree.textBackground` now has a valid color and is no longer `null`. diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 59fece800..3d708d7e0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -28,6 +28,7 @@ import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.lang.ref.WeakReference; import java.util.List; import java.util.function.Consumer; import java.util.logging.Level; @@ -66,6 +67,7 @@ public abstract class FlatLaf private KeyEventPostProcessor mnemonicListener; private static boolean showMnemonics; + private static WeakReference lastShowMnemonicWindow; private Consumer postInitialization; @@ -391,18 +393,28 @@ private static void showMnemonics( boolean show ) { if( !UIManager.getBoolean( "Component.hideMnemonics" ) ) return; - // get focus owner - Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if( focusOwner == null ) - return; + if( show ) { + // get focus owner + Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if( focusOwner == null ) + return; - // get focused window - Window window = SwingUtilities.windowForComponent( focusOwner ); - if( window == null ) - return; + // get focused window + Window window = SwingUtilities.windowForComponent( focusOwner ); + if( window == null ) + return; + + // repaint components with mnemonics in focused window + repaintMnemonics( window ); - // repaint components with mnemonics in focused window - repaintMnemonics( window ); + lastShowMnemonicWindow = new WeakReference<>( window ); + } else if( lastShowMnemonicWindow != null ) { + Window window = lastShowMnemonicWindow.get(); + if( window != null ) + repaintMnemonics( window ); + + lastShowMnemonicWindow = null; + } } private static void repaintMnemonics( Container container ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java index 5679af31b..f1cb3767d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java @@ -17,8 +17,11 @@ package com.formdev.flatlaf.ui; import static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Graphics; +import java.awt.Rectangle; import java.beans.PropertyChangeListener; import javax.swing.JComponent; +import javax.swing.JMenuItem; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI; @@ -74,4 +77,9 @@ protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { defaultTextIconGap = scale( defaultTextIconGap ); }; } + + @Override + protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { + FlatMenuItemUI.paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java index 205c75cab..28c769996 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java @@ -17,10 +17,18 @@ package com.formdev.flatlaf.ui; import static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Rectangle; import java.beans.PropertyChangeListener; +import javax.swing.ButtonModel; import javax.swing.JComponent; +import javax.swing.JMenu; +import javax.swing.JMenuItem; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuItemUI; +import com.formdev.flatlaf.FlatLaf; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JMenuItem}. @@ -74,4 +82,26 @@ protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { defaultTextIconGap = scale( defaultTextIconGap ); }; } + + @Override + protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { + paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + } + + public static void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, + String text, Color disabledForeground, Color selectionForeground ) + { + FontMetrics fm = menuItem.getFontMetrics( menuItem.getFont() ); + int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1; + + ButtonModel model = menuItem.getModel(); + g.setColor( !model.isEnabled() + ? disabledForeground + : (model.isArmed() || (menuItem instanceof JMenu && model.isSelected()) + ? selectionForeground + : menuItem.getForeground()) ); + + FlatUIUtils.drawStringUnderlineCharAt( menuItem, g, text, mnemonicIndex, + textRect.x, textRect.y + fm.getAscent() ); + } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java index a1ab13e26..3706b564b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java @@ -17,8 +17,11 @@ package com.formdev.flatlaf.ui; import static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Graphics; +import java.awt.Rectangle; import java.beans.PropertyChangeListener; import javax.swing.JComponent; +import javax.swing.JMenuItem; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuUI; @@ -77,4 +80,9 @@ protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { defaultTextIconGap = scale( defaultTextIconGap ); }; } + + @Override + protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { + FlatMenuItemUI.paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java index 114525d26..ef55d3ec6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java @@ -17,8 +17,11 @@ package com.formdev.flatlaf.ui; import static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Graphics; +import java.awt.Rectangle; import java.beans.PropertyChangeListener; import javax.swing.JComponent; +import javax.swing.JMenuItem; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI; @@ -74,4 +77,9 @@ protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { defaultTextIconGap = scale( defaultTextIconGap ); }; } + + @Override + protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { + FlatMenuItemUI.paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + } } diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java index 11fcd6af7..9a7c52081 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java @@ -51,6 +51,12 @@ private void selectedTabChanged() { DemoPrefs.getState().putInt( FlatLafDemo.KEY_TAB, tabbedPane.getSelectedIndex() ); } + private void menuItemActionPerformed(ActionEvent e) { + SwingUtilities.invokeLater( () -> { + JOptionPane.showMessageDialog( this, e.getActionCommand(), "Menu Item", JOptionPane.PLAIN_MESSAGE ); + } ); + } + private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents JMenuBar menuBar1 = new JMenuBar(); @@ -68,6 +74,14 @@ private void initComponents() { JMenuItem deleteMenuItem = new JMenuItem(); JMenu viewMenu = new JMenu(); JCheckBoxMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem(); + JMenu menu1 = new JMenu(); + JMenu subViewsMenu = new JMenu(); + JMenu subSubViewsMenu = new JMenu(); + JMenuItem errorLogViewMenuItem = new JMenuItem(); + JMenuItem searchViewMenuItem = new JMenuItem(); + JMenuItem projectViewMenuItem = new JMenuItem(); + JMenuItem structureViewMenuItem = new JMenuItem(); + JMenuItem propertiesViewMenuItem = new JMenuItem(); JRadioButtonMenuItem radioButtonMenuItem1 = new JRadioButtonMenuItem(); JRadioButtonMenuItem radioButtonMenuItem2 = new JRadioButtonMenuItem(); JRadioButtonMenuItem radioButtonMenuItem3 = new JRadioButtonMenuItem(); @@ -103,27 +117,35 @@ private void initComponents() { //======== fileMenu ======== { fileMenu.setText("File"); + fileMenu.setMnemonic('F'); //---- newMenuItem ---- newMenuItem.setText("New"); newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + newMenuItem.setMnemonic('N'); + newMenuItem.addActionListener(e -> menuItemActionPerformed(e)); fileMenu.add(newMenuItem); //---- openMenuItem ---- openMenuItem.setText("Open"); openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + openMenuItem.setMnemonic('O'); + openMenuItem.addActionListener(e -> menuItemActionPerformed(e)); fileMenu.add(openMenuItem); fileMenu.addSeparator(); //---- closeMenuItem ---- closeMenuItem.setText("Close"); closeMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + closeMenuItem.setMnemonic('C'); + closeMenuItem.addActionListener(e -> menuItemActionPerformed(e)); fileMenu.add(closeMenuItem); fileMenu.addSeparator(); //---- exitMenuItem ---- exitMenuItem.setText("Exit"); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + exitMenuItem.setMnemonic('X'); exitMenuItem.addActionListener(e -> exitActionPerformed()); fileMenu.add(exitMenuItem); } @@ -132,37 +154,50 @@ private void initComponents() { //======== editMenu ======== { editMenu.setText("Edit"); + editMenu.setMnemonic('E'); //---- undoMenuItem ---- undoMenuItem.setText("Undo"); undoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + undoMenuItem.setMnemonic('U'); + undoMenuItem.addActionListener(e -> menuItemActionPerformed(e)); editMenu.add(undoMenuItem); //---- redoMenuItem ---- redoMenuItem.setText("Redo"); redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + redoMenuItem.setMnemonic('R'); + redoMenuItem.addActionListener(e -> menuItemActionPerformed(e)); editMenu.add(redoMenuItem); editMenu.addSeparator(); //---- cutMenuItem ---- cutMenuItem.setText("Cut"); cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + cutMenuItem.setMnemonic('C'); + cutMenuItem.addActionListener(e -> menuItemActionPerformed(e)); editMenu.add(cutMenuItem); //---- copyMenuItem ---- copyMenuItem.setText("Copy"); copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + copyMenuItem.setMnemonic('O'); + copyMenuItem.addActionListener(e -> menuItemActionPerformed(e)); editMenu.add(copyMenuItem); //---- pasteMenuItem ---- pasteMenuItem.setText("Paste"); pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + pasteMenuItem.setMnemonic('P'); + pasteMenuItem.addActionListener(e -> menuItemActionPerformed(e)); editMenu.add(pasteMenuItem); editMenu.addSeparator(); //---- deleteMenuItem ---- deleteMenuItem.setText("Delete"); deleteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); + deleteMenuItem.setMnemonic('D'); + deleteMenuItem.addActionListener(e -> menuItemActionPerformed(e)); editMenu.add(deleteMenuItem); } menuBar1.add(editMenu); @@ -170,24 +205,84 @@ private void initComponents() { //======== viewMenu ======== { viewMenu.setText("View"); + viewMenu.setMnemonic('V'); //---- checkBoxMenuItem1 ---- checkBoxMenuItem1.setText("Show Toolbar"); checkBoxMenuItem1.setSelected(true); + checkBoxMenuItem1.setMnemonic('T'); + checkBoxMenuItem1.addActionListener(e -> menuItemActionPerformed(e)); viewMenu.add(checkBoxMenuItem1); + + //======== menu1 ======== + { + menu1.setText("Show View"); + menu1.setMnemonic('V'); + + //======== subViewsMenu ======== + { + subViewsMenu.setText("Sub Views"); + subViewsMenu.setMnemonic('S'); + + //======== subSubViewsMenu ======== + { + subSubViewsMenu.setText("Sub sub Views"); + subSubViewsMenu.setMnemonic('U'); + + //---- errorLogViewMenuItem ---- + errorLogViewMenuItem.setText("Error Log"); + errorLogViewMenuItem.setMnemonic('E'); + errorLogViewMenuItem.addActionListener(e -> menuItemActionPerformed(e)); + subSubViewsMenu.add(errorLogViewMenuItem); + } + subViewsMenu.add(subSubViewsMenu); + + //---- searchViewMenuItem ---- + searchViewMenuItem.setText("Search"); + searchViewMenuItem.setMnemonic('S'); + searchViewMenuItem.addActionListener(e -> menuItemActionPerformed(e)); + subViewsMenu.add(searchViewMenuItem); + } + menu1.add(subViewsMenu); + + //---- projectViewMenuItem ---- + projectViewMenuItem.setText("Project"); + projectViewMenuItem.setMnemonic('P'); + projectViewMenuItem.addActionListener(e -> menuItemActionPerformed(e)); + menu1.add(projectViewMenuItem); + + //---- structureViewMenuItem ---- + structureViewMenuItem.setText("Structure"); + structureViewMenuItem.setMnemonic('T'); + structureViewMenuItem.addActionListener(e -> menuItemActionPerformed(e)); + menu1.add(structureViewMenuItem); + + //---- propertiesViewMenuItem ---- + propertiesViewMenuItem.setText("Properties"); + propertiesViewMenuItem.setMnemonic('O'); + propertiesViewMenuItem.addActionListener(e -> menuItemActionPerformed(e)); + menu1.add(propertiesViewMenuItem); + } + viewMenu.add(menu1); viewMenu.addSeparator(); //---- radioButtonMenuItem1 ---- radioButtonMenuItem1.setText("Details"); radioButtonMenuItem1.setSelected(true); + radioButtonMenuItem1.setMnemonic('D'); + radioButtonMenuItem1.addActionListener(e -> menuItemActionPerformed(e)); viewMenu.add(radioButtonMenuItem1); //---- radioButtonMenuItem2 ---- radioButtonMenuItem2.setText("Small Icons"); + radioButtonMenuItem2.setMnemonic('S'); + radioButtonMenuItem2.addActionListener(e -> menuItemActionPerformed(e)); viewMenu.add(radioButtonMenuItem2); //---- radioButtonMenuItem3 ---- radioButtonMenuItem3.setText("Large Icons"); + radioButtonMenuItem3.setMnemonic('L'); + radioButtonMenuItem3.addActionListener(e -> menuItemActionPerformed(e)); viewMenu.add(radioButtonMenuItem3); } menuBar1.add(viewMenu); @@ -195,9 +290,11 @@ private void initComponents() { //======== helpMenu ======== { helpMenu.setText("Help"); + helpMenu.setMnemonic('H'); //---- aboutMenuItem ---- aboutMenuItem.setText("About"); + aboutMenuItem.setMnemonic('A'); aboutMenuItem.addActionListener(e -> aboutActionPerformed()); helpMenu.add(aboutMenuItem); } diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd index 7c6528328..4912b2541 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd @@ -1,4 +1,4 @@ -JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8" new FormModel { contentType: "form/swing" @@ -117,15 +117,20 @@ new FormModel { add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "fileMenu" "text": "File" + "mnemonic": 70 add( new FormComponent( "javax.swing.JMenuItem" ) { name: "newMenuItem" "text": "New" "accelerator": static javax.swing.KeyStroke getKeyStroke( 78, 4226, false ) + "mnemonic": 78 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JMenuItem" ) { name: "openMenuItem" "text": "Open" "accelerator": static javax.swing.KeyStroke getKeyStroke( 79, 4226, false ) + "mnemonic": 79 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { name: "separator2" @@ -134,6 +139,8 @@ new FormModel { name: "closeMenuItem" "text": "Close" "accelerator": static javax.swing.KeyStroke getKeyStroke( 87, 4226, false ) + "mnemonic": 67 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { name: "separator1" @@ -142,21 +149,27 @@ new FormModel { name: "exitMenuItem" "text": "Exit" "accelerator": static javax.swing.KeyStroke getKeyStroke( 81, 4226, false ) + "mnemonic": 88 addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "exitActionPerformed", false ) ) } ) } ) add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "editMenu" "text": "Edit" + "mnemonic": 69 add( new FormComponent( "javax.swing.JMenuItem" ) { name: "undoMenuItem" "text": "Undo" "accelerator": static javax.swing.KeyStroke getKeyStroke( 90, 4226, false ) + "mnemonic": 85 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JMenuItem" ) { name: "redoMenuItem" "text": "Redo" "accelerator": static javax.swing.KeyStroke getKeyStroke( 89, 4226, false ) + "mnemonic": 82 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { name: "separator4" @@ -165,16 +178,22 @@ new FormModel { name: "cutMenuItem" "text": "Cut" "accelerator": static javax.swing.KeyStroke getKeyStroke( 88, 4226, false ) + "mnemonic": 67 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JMenuItem" ) { name: "copyMenuItem" "text": "Copy" "accelerator": static javax.swing.KeyStroke getKeyStroke( 67, 4226, false ) + "mnemonic": 79 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JMenuItem" ) { name: "pasteMenuItem" "text": "Paste" "accelerator": static javax.swing.KeyStroke getKeyStroke( 86, 4226, false ) + "mnemonic": 80 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { name: "separator3" @@ -183,15 +202,65 @@ new FormModel { name: "deleteMenuItem" "text": "Delete" "accelerator": static javax.swing.KeyStroke getKeyStroke( 127, 0, false ) + "mnemonic": 68 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) } ) add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "viewMenu" "text": "View" + "mnemonic": 86 add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { name: "checkBoxMenuItem1" "text": "Show Toolbar" "selected": true + "mnemonic": 84 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) + } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "menu1" + "text": "Show View" + "mnemonic": 86 + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "subViewsMenu" + "text": "Sub Views" + "mnemonic": 83 + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "subSubViewsMenu" + "text": "Sub sub Views" + "mnemonic": 85 + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "errorLogViewMenuItem" + "text": "Error Log" + "mnemonic": 69 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) + } ) + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "searchViewMenuItem" + "text": "Search" + "mnemonic": 83 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) + } ) + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "projectViewMenuItem" + "text": "Project" + "mnemonic": 80 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "structureViewMenuItem" + "text": "Structure" + "mnemonic": 84 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "propertiesViewMenuItem" + "text": "Properties" + "mnemonic": 79 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) + } ) } ) add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { name: "separator8" @@ -201,24 +270,32 @@ new FormModel { "text": "Details" "selected": true "$buttonGroup": new FormReference( "buttonGroup1" ) + "mnemonic": 68 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { name: "radioButtonMenuItem2" "text": "Small Icons" "$buttonGroup": new FormReference( "buttonGroup1" ) + "mnemonic": 83 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { name: "radioButtonMenuItem3" "text": "Large Icons" "$buttonGroup": new FormReference( "buttonGroup1" ) + "mnemonic": 76 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuItemActionPerformed", true ) ) } ) } ) add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "helpMenu" "text": "Help" + "mnemonic": 72 add( new FormComponent( "javax.swing.JMenuItem" ) { name: "aboutMenuItem" "text": "About" + "mnemonic": 65 addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "aboutActionPerformed", false ) ) } ) } ) diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java index 908f89cc2..52d8390aa 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java @@ -126,13 +126,16 @@ private void initComponents() { //======== menu5 ======== { menu5.setText("text"); + menu5.setMnemonic('T'); //---- menuItem7 ---- menuItem7.setText("text"); + menuItem7.setMnemonic('X'); menu5.add(menuItem7); //---- menuItem8 ---- menuItem8.setText("text"); + menuItem8.setMnemonic('E'); menu5.add(menuItem8); } menuBar1.add(menu5); @@ -175,6 +178,7 @@ private void initComponents() { //======== menu1 ======== { menu1.setText("enabled"); + menu1.setMnemonic('E'); } panel1.add(menu1, "cell 1 0"); @@ -185,6 +189,7 @@ private void initComponents() { //---- menuItem1 ---- menuItem1.setText("enabled"); menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK)); + menuItem1.setMnemonic('N'); panel1.add(menuItem1, "cell 1 1"); //---- checkBoxMenuItemLabel ---- @@ -194,6 +199,7 @@ private void initComponents() { //---- checkBoxMenuItem1 ---- checkBoxMenuItem1.setText("enabled"); checkBoxMenuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); + checkBoxMenuItem1.setMnemonic('A'); panel1.add(checkBoxMenuItem1, "cell 1 2"); //---- radioButtonMenuItemLabel ---- @@ -203,6 +209,7 @@ private void initComponents() { //---- radioButtonMenuItem1 ---- radioButtonMenuItem1.setText("enabled"); radioButtonMenuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); + radioButtonMenuItem1.setMnemonic('B'); panel1.add(radioButtonMenuItem1, "cell 1 3"); //---- popupMenuSeparatorLabel ---- @@ -230,6 +237,7 @@ private void initComponents() { { menu2.setText("disabled"); menu2.setEnabled(false); + menu2.setMnemonic('D'); } panel2.add(menu2, "cell 0 0"); @@ -237,18 +245,21 @@ private void initComponents() { menuItem2.setText("disabled"); menuItem2.setEnabled(false); menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.ALT_MASK|KeyEvent.SHIFT_MASK)); + menuItem2.setMnemonic('I'); panel2.add(menuItem2, "cell 0 1"); //---- checkBoxMenuItem2 ---- checkBoxMenuItem2.setText("disabled"); checkBoxMenuItem2.setEnabled(false); checkBoxMenuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); + checkBoxMenuItem2.setMnemonic('S'); panel2.add(checkBoxMenuItem2, "cell 0 2"); //---- radioButtonMenuItem2 ---- radioButtonMenuItem2.setText("disabled"); radioButtonMenuItem2.setEnabled(false); radioButtonMenuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); + radioButtonMenuItem2.setMnemonic('L'); panel2.add(radioButtonMenuItem2, "cell 0 3"); } add(panel2, "cell 2 1"); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd index bc2ff51be..2700ef0bf 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd @@ -1,4 +1,4 @@ -JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8" new FormModel { contentType: "form/swing" @@ -23,13 +23,16 @@ new FormModel { add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "menu5" "text": "text" + "mnemonic": 84 add( new FormComponent( "javax.swing.JMenuItem" ) { name: "menuItem7" "text": "text" + "mnemonic": 88 } ) add( new FormComponent( "javax.swing.JMenuItem" ) { name: "menuItem8" "text": "text" + "mnemonic": 69 } ) } ) add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { @@ -63,6 +66,7 @@ new FormModel { add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "menu1" "text": "enabled" + "mnemonic": 69 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 0" } ) @@ -76,6 +80,7 @@ new FormModel { name: "menuItem1" "text": "enabled" "accelerator": static javax.swing.KeyStroke getKeyStroke( 65, 130, false ) + "mnemonic": 78 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 1" } ) @@ -89,6 +94,7 @@ new FormModel { name: "checkBoxMenuItem1" "text": "enabled" "accelerator": &KeyStroke0 static javax.swing.KeyStroke getKeyStroke( 112, 0, false ) + "mnemonic": 65 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 2" } ) @@ -102,6 +108,7 @@ new FormModel { name: "radioButtonMenuItem1" "text": "enabled" "accelerator": #KeyStroke0 + "mnemonic": 66 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 3" } ) @@ -130,6 +137,7 @@ new FormModel { name: "menu2" "text": "disabled" "enabled": false + "mnemonic": 68 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 0" } ) @@ -138,6 +146,7 @@ new FormModel { "text": "disabled" "enabled": false "accelerator": static javax.swing.KeyStroke getKeyStroke( 68, 585, false ) + "mnemonic": 73 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 1" } ) @@ -146,6 +155,7 @@ new FormModel { "text": "disabled" "enabled": false "accelerator": #KeyStroke0 + "mnemonic": 83 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 2" } ) @@ -154,6 +164,7 @@ new FormModel { "text": "disabled" "enabled": false "accelerator": #KeyStroke0 + "mnemonic": 76 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 3" } )