Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6449338

JMenuitem titles not painted if horizontal alignment is not LEFT nor LEADING

XMLWordPrintable

      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.

            alexp Alexander Potochkin (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: