Haeri
Haeri

Reputation: 701

JMenuItem shortcut alignment

I have a JMenuBar with the standard items and shortcuts. But I noticed that the shortcut description is left-aligned, which looks ugly. Is there a way to right-align it?

PS: "Umschalt" means shift. Is there a way to force it to say shift instead of Umschalt?

[UPDATE: Locale.setDefault(Locale.ENGLISH); fixes the problem, but a solution to only affect specific components would be better.. ]

PSPS: With UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); I have set the look and feel to be OS default. But now I would like to make some small adjustments to the look on top of the standard OS Look. For example I would like to make the JMenuBar black. The interwebs told me to use UIManager.put("tMenuBar.background", Color.BLACK); but it doesn't seem to do anything..

[UPDATE: It seems like this is not possible with Windows Look and feel :/]

enter image description here

Here the code:

    private JMenuBar tMenuBar;
    private JMenu mbEdit;
    private JMenuItem mCut, mCopy, mPaste, mDo, mUndo;

    tMenuBar = new JMenuBar();
    mbEdit = new JMenu("Edit");
    tMenuBar.add(mbEdit);

    // EDIT
    mUndo = new JMenuItem("Undo");
    mDo = new JMenuItem("Redo");
    mCut = new JMenuItem("Cut");
    mCut.setIcon(iCut);
    mCopy = new JMenuItem("Copy");
    mCopy.setIcon(iCopy);
    mPaste = new JMenuItem("Paste");
    mPaste.setIcon(iPaste);
    mbEdit.add(mUndo);
    mbEdit.add(mDo);
    mbEdit.addSeparator();
    mbEdit.add(mCut);
    mbEdit.add(mCopy);
    mbEdit.add(mPaste);

    // Undo
    mUndo.setAccelerator(KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    // Redo
    mDo.setAccelerator(KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_Z, ((Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | java.awt.event.InputEvent.SHIFT_MASK))));
    // Cut
    mCut.setAccelerator(KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    // Copy
    mCopy.setAccelerator(KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    // Paste
    mPaste.setAccelerator(KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

Already tried:

applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

enter image description here

Upvotes: 3

Views: 369

Answers (2)

Iootu
Iootu

Reputation: 344

Take a look at this post regarding the german words. I do realize that this was probably a comment rather than an answer but I'm still unable to do those due to the lack of reputation and I want to help.

Upvotes: 1

camickr
camickr

Reputation: 324137

I would like to make the JMenuBar black.

It should be (with the "t")

UIManager.put("MenuBar.background", Color.BLACK);

You need to set the UIManager properties "before" you create the component.

Also, the property may not be supported on all LAF's. Check out UIManager Defaults for more information and a list of the properties support by LAF.

Upvotes: 1

Related Questions