JDK-6449338 : JMenuitem titles not painted if horizontal alignment is not LEFT nor LEADING
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2006-07-17
  • Updated: 2011-02-16
  • Resolved: 2006-08-11
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)

  Bug also happens in Windows XP Proffesional

ADDITIONAL OS VERSION INFORMATION :
Linux robocop.visual-tools.com 2.6.16-1-686 #2 Thu May 4 18:22:23 UTC 2006 i686 GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
Nothing special, running Debian unstable. Bug also happens in Windows XP Professional

A DESCRIPTION OF THE PROBLEM :
If I call setHorizontalAlignment() for my JMenuItem's inside my JPopupMenu with any of SwingConstants.CENTER, TRAILING (en_ie locale), or RIGHT values as the alignment parameter, the strings for the titles of the menu items are not painted.

They are painted, however, if LEFT or LEADING is  used.

This is happening on both Windows XP pro and Linux i586.

It did not happen with latest Java 5.0: Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode), but does on latest Mustang beta2 release.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please compile and run the test case attached to the bug report. Press right mouse button for the popup to show over the button. It can be noticed how the titles for all any of the menu items are not painted.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The title strings for the menu items to be painted.
ACTUAL -
The title strings for the menu items are not painted.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package popupbugtestcase;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UnsupportedLookAndFeelException;

public class PopUpTestFrame extends JFrame implements MouseListener {

    private static final long serialVersionUID = -5218570971611916714L;

    private JButton button;

    class MyPopUpMenu extends JPopupMenu {

        private static final long serialVersionUID = 6319308143840167827L;

        public MyPopUpMenu() {
            super();
            
            JMenuItem menuItem1 = new JMenuItem("Menu Item 1");
            // -----------------------------------------------------------
            // This makes the pop up menu not paint any menu item titles:
            menuItem1.setHorizontalAlignment(SwingConstants.CENTER);
            // Problem also happens for CENTER, RIGHT or TRAILING
            // (en_ie locale)
            // -----------------------------------------------------------
            add(menuItem1);

            JMenuItem menuItem2 = new JMenuItem("Menu Item 2");
            add(menuItem2);
        }
        
    }
    
    public PopUpTestFrame() {
        super("Pop Up Test");
        
        setLayout(new BorderLayout());
        
        button = new JButton("PopUp");
        button.addMouseListener(this);
        
        add(button, BorderLayout.CENTER);
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        if (e.isPopupTrigger()) {
            showPopUp(e);
        }
    }

    public void mouseReleased(MouseEvent e) {
        if (e.isPopupTrigger()) {
            showPopUp(e);
        }
    }
    
    private void showPopUp(MouseEvent e) {
        JPopupMenu popUp = new MyPopUpMenu();
        popUp.show(e.getComponent(), e.getX(), e.getY());
    }
    
    public static void main(String[] args)
    throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                PopUpTestFrame f = new PopUpTestFrame();
                f.setSize(new Dimension(200, 200));
                f.setVisible(true);
            }
        });
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Not setting menu item's horizontal alignment to CENTER, nor TRAILING, nor RIGHT.

Release Regression From : 5.0u7
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION The cause of the 6449338 regression is the fix for 4729669: 1.4 REGRESSION: Text edge of different types of JMenuItems are not aligned The fix adds offsets in BasicMenuItemUI to calculate x coordinates of icon and text. It is not so good idea, because it doesn't take in the account the horizontal alignment.
04-08-2006

EVALUATION I wrote a new menu item layout algorithm, which solves all the layout problems (including 6449338). We assumed to put back it as a fix for the 6438430. But it is too risky to integrate such large changes in mustang b96. We decided to defer this large fix to an update release and to fix only regressions. Consequently, a fix for 6438430 is not solves 6449338 and I have to reopen the last one.
04-08-2006

EVALUATION This bug will be eliminated after 6438430 is fixed closed as duplicate
24-07-2006

EVALUATION I can reproduce the bug. It looks ugly. I'm working on a fix for the 6438430 bug, which should remove the problem.
20-07-2006