JMenuItem label alignment

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

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

[ UPDATE: Locale.setDefault(Locale.ENGLISH);

fixes the problem, but a solution that only affects specific components would be better ..]

PSPS: With UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

I set the default OS appearance. But now I would like to make small adjustments to the appearance of the standard OS Look. For example, I would like to make the JMenuBar black. Intervez told me to use UIManager.put("tMenuBar.background", Color.BLACK);

but it doesn't do anything.

[ UPDATE: It looks like this is not possible on Windows. Look and feel: /]

enter image description here

Here's 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()));

      

Have already tried:

applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

      

enter image description here

+3


source to share


2 answers


I would like to make the JMenuBar black.

It should be (with "t")

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

      



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

Also, the property may not be supported in all LAFs. Run UIManager Defaults for more information and a list of property support with LAF.

+1


source


Take a look at this post regarding German words. I realize this is more of a comment than an answer, but I still cannot do it due to lack of reputation and I want to help.



+1


source







All Articles