Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mnemonics in menus are always displayed #43

Closed
Chrriis opened this issue Jan 13, 2020 · 14 comments
Closed

Mnemonics in menus are always displayed #43

Chrriis opened this issue Jan 13, 2020 · 14 comments
Labels
bug Something isn't working
Milestone

Comments

@Chrriis
Copy link
Contributor

Chrriis commented Jan 13, 2020

With the system L&F (Windows 10), mnemonics are not displayed in menus unless I press the Alt key. With FlatLaf, mnemonics are always displayed.

I see that the FlatLaf code triggers repainting on the hierarchy when Alt is pressed or released, but this has no visual impact.

Unless I am mistaken, FlatMenuUI extends BasicMenuUI, and BasicMenuUI always paints the mnemonic. WindowsMenuItemUI (for system L&F) also extends BasicMenuItemUI but overrides paintText to have the mnemonic show/hide logic.

Please, let me know if I did something wrong 🙂

@DevCharly
Copy link
Collaborator

Mnemonic hiding was only implemented for labels, buttons and tabs.
Seems that I forgot the menus...

However, this is now implemented in master branch.

@Chrriis
Copy link
Contributor Author

Chrriis commented Jan 14, 2020

The fix works.

Minor details with regards to the Alt-key behavior (at least on Windows):

  • If the window does not have a component with focus, then the fix does not work with FlatLaf.
  • Pressing Alt on Windows L&F reveals the mnemonics but releasing it selects the first menu from the menu bar, which is not the case with FlatLaf.

Here is a test case:

	public static void main(String[] args) throws Exception {
//		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		UIManager.setLookAndFeel(new FlatLightLaf());
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JMenuBar menuBar = new JMenuBar();
		JMenu menu1 = new JMenu("Menu 1");
		menu1.setMnemonic('m');
		JMenuItem subMenu1_1 = new JMenuItem("Sub Menu 1.1");
		subMenu1_1.setMnemonic('s');
		menu1.add(subMenu1_1);
		menuBar.add(menu1);
		frame.setJMenuBar(menuBar);
//		frame.setContentPane(new JScrollPane(new JTextArea()));
		frame.setSize(400, 300);
		frame.setVisible(true);
	}

You can easily swap with the native L&F to see the difference (first comment), and you can easily add a focusable component (second comment).

@DevCharly DevCharly added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Jan 15, 2020
DevCharly added a commit that referenced this issue Jan 17, 2020
@tanmatra
Copy link

Ok, now how I can disable this feature if I don't like it?

@DevCharly
Copy link
Collaborator

No problem. See "Show Mnemonics" section here: https://www.formdev.com/flatlaf/customizing/#show_mnemonics

@Chrriis
Copy link
Contributor Author

Chrriis commented Jan 20, 2020

I checked the latest changes and here are the current issues I found:

  • if I Alt+Tab to switch to another window, and Alt+tab back, the mnemonics are showing while they should not.
  • Pressing Alt on Windows L&F reveals the mnemonics but releasing it selects the first menu from the menu bar, which is not the case with FlatLaf. This is convenient for keyboard navigation when menus/submenus do not have mnemonics.

@DevCharly
Copy link
Collaborator

Chrriis wrote:

I don't know if this commit is responsible for a regression, but when I activate a parent menu by clicking, the mnemonics show!
MenuShowingMnemonics

No, commit 870d039 only hides the mnemonic when deactivating window (e.g. Alt+Tab to other window). This addresses the first point in #43 (comment)

Commit e3ed47b is responsible for showing mnemonics as soon as menu bar is active or a popup menu is visible.

What's wrong with this?
You can open a menu with the mouse, see the mnemonics and then execute an item with an mnemonic key. When you activate the menu with Alt+M then the mnemonics are also shown.

@Chrriis
Copy link
Contributor Author

Chrriis commented Apr 30, 2020

Well, mnemonics are noisy indications, so the original feature got tweaked to only reveal them when you press Alt. Activating a menu and having the UI blink everywhere with the mnemonics suddenly appearing is very odd.

@Chrriis
Copy link
Contributor Author

Chrriis commented Apr 30, 2020

As an additional comment, mnemonics are useful for people who want to use their keyboard to quickly jump. Basic users would simply use their mouse and they absolutely do not care about mnemonics and the graphical noise they add. Showing mnemonics on mouse actions is very odd.

@DevCharly
Copy link
Collaborator

Ok, thanks for your feedback. Sounds reasonable. I'll change it...

DevCharly added a commit that referenced this issue May 1, 2020
@Chrriis
Copy link
Contributor Author

Chrriis commented May 1, 2020

The behaviour of the mnemonics is much better with that last commit!

Now if I wanted to be picky, the only remaining issue I know is that pressing and releasing "Alt" on Windows should have the same effect than your F10 action (i.e. arm the first menu). Instead, it focuses on the top left icon of the window, and the proof is that if I press arrow down, it reveals the window icon top menu:
MenuAlt

@DevCharly
Copy link
Collaborator

Now if I wanted to be picky, ...

Don't stop 😉 This brings FlatLaf forward. Details matter.

Activating menu with Alt key (on Windows) is now implemented in master branch.

@Chrriis
Copy link
Contributor Author

Chrriis commented May 4, 2020

Activating menu with Alt key (on Windows) is now implemented

Much better indeed.
I found that when you alt+tab to a different window and come back using alt+tab, Alt does not arm the menu the first time you press it. I personally do not care much about this issue though, and I find that other programs have similar problems (Eclipse activates the mnemonics for example).

DevCharly added a commit that referenced this issue May 4, 2020
@DevCharly
Copy link
Collaborator

Good catch 👍
Fixed in master

@smileatom
Copy link

good job guys.

@DevCharly DevCharly added this to the 0.34 milestone May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants