JDK-6462368 : JMenuItem Icon not displayed in JMenuBar
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-08-22
  • Updated: 2011-02-16
  • Resolved: 2006-08-23
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b96)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b96, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
I have a JMenuItem with a Icon.
This JMenuItem ist directly added to a JMenuBar.
The Icon is not displayed (just a grey rectangle).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Here is a simple test-file to reproduce the bug.
You only must change the path to the ImageIcon (i can not attach the 
icon, you must use your own ;))

---------- BEGIN SOURCE ----------
import javax.swing.*;


public class JMenuIconBug {


    private static void createAndShowGUI() {
        JFrame frame = new JFrame("TEST");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300,100);
        JMenuItem jmi_TTCLogo = new JMenuItem(new 
ImageIcon("images/1.png")); //$NON-NLS-1$
        jmi_TTCLogo.setHorizontalAlignment(SwingConstants.RIGHT);
        jmi_TTCLogo.setRolloverEnabled(false);
        jmi_TTCLogo.setText("  "); //$NON-NLS-1$
        JMenuBar jmb = new JMenuBar();
        jmb.add(jmi_TTCLogo);
        frame.setJMenuBar(jmb);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

}

---------- END SOURCE ----------
REPRODUCIBILITY :
This bug can be reproduced always.

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

Comments
EVALUATION Exactly, it is a duplicate of 6458123, item 4: if the horizontal alignment of an menu item differs from the default (LEADING), text and icon of all menu items in the same menu are out of view. The test case uses JMenuItem.setHorizontalAlignment(SwingConstants.RIGHT). I close the bug as duplicate of 6458123.
23-08-2006

EVALUATION This looks like a duplicate of 6458123. Will let the responsible engineer decide.
22-08-2006