Wednesday, 7 August 2013

How can I add to or change a label on a JMenuItem?

How can I add to or change a label on a JMenuItem?

I need to add a label on the right hand side of a JMenuItem, like the
labels shown below:

I have an application that uses Ctrl++ and Ctrl+- to zoom into an image.
However, the + key by default (without Shift) is the = key. When I try
adding accelerators for these menu items, the Ctrl+- shortcut label
displays as "Ctrl+Minus" (somewhat undesirable) and the Ctrl++ shortcut
label displays as "Ctrl+Equals" (even worse, since it should be
Ctrl+Plus):
menuBar_view_zoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS,
ActionEvent.CTRL_MASK));

I want Ctrl++ to display as "Ctrl+ +" and Ctrl+- to display as "Ctrl+ -".
How can this be done?

No comments:

Post a Comment