質問

I have a Java application with a JFrame that contains a JMenuBar. I am using the Windows L&F.

When the JMenuBar is active, the selected JMenu is highlighted. The user can move to the previous/next JMenu by pressing the left/right arrows keys.

The problem I am having is with disabled JMenus. In the Windows L&F, disabled JMenus are not skipped when traversed with the arrow keys and they are also not highlighted. When the user moves onto a disabled JMenu, there is no visual clue as to where he is.

Is there any way to modify the JMenuBar behavior so that it skips disabled JMenus?

役に立ちましたか?

解決

Trying to figure out how navigation is done, I was looking at BasicPopupMenuUI where I found two methods called next/previousEnabledChild(...) that are checking the following UIManager property:

UIManager.getBoolean("MenuItem.disabledAreNavigable")

So after setting the LAF to windows I add the following line of code:

UIManager.put("MenuItem.disabledAreNavigable", Boolean.FALSE);

and it now works as you expect.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top