Details

    • Subcomponent:
    • Resolved In Build:
      b20
    • CPU:
      generic, x86
    • OS:
      generic, linux, windows_xp
    • Verification:
      Not verified

      Backports

        Description

        JDK version: mustang b96
        Platform: Windows XP SP2

        There are several bugs in menu item layout (see the attached test case MenuItemLayoutProblems):

        1. Accelerator texts are layouted in a wrong way if menu orientation is Right-to-Left. See the "First R2L" menu ("Text and Accelerator" and "CheckBox, icon and Accelerator" items).

        2. If there are items with the "CENTER" text alignment, menu item preferred size is wider, than must be. See the "Second L2R" and "Second R2L" menus.

        3. If icon is wider than text and text alignment is the "CENTER", menu item is layouted in a wrong way. See the "Second L2R" and "Second R2L" menus (the "small text" 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. See the "Third L2R" and "Third R2L" menus.

        5. Under GTK LaF icons of check box and radio menu items are shifted by couple of pixels relative to icons of other menu items. Select GTK LaF and see the "First L2R" and "First R2L" menus.

        6. Under GTK LaF the accelerator text sometimes overlaps with the text of menu item. Select GTK LaF and see the "Second L2R" menu ("Radio Button, icon at the center and below text" and "Check Box, icon at the center and above text" items)
        There is another user reported bug: http://forums.java.net/jive/thread.jspa?messageID=188078&#188078

        One of Substance users has reported a regression behaviour on menu items.

        The test case is below. If run under 5.0, the texts are not aligned (usual behaviour). Under 6.0, the texts are aligned, but the icon of the first menu item overlaps with the text of that item. Note that this test case requires menu items with icons of different size + the smaller one being installed on checkbox menu item.

        In addition, when this test is run in WindowsLookAndFeel, the text alignment and icon alignment is OK (no overlapping), but the check mark of radio button menu item has (hard) square bottom left corner.

        Most likely it is a regression of the fix for 4729669 (1.4 REGRESSION: Text edge of different types of JMenuItems are not aligned) introduced in Mustang.

        =============Source start===============
        import java.awt.*;

        import javax.swing.*;
        import javax.swing.plaf.metal.MetalLookAndFeel;

        public class NewBugTest extends JFrame {
            NewBugTest() {
                JMenuBar jmb = new JMenuBar();
                JMenu menu = new JMenu("menu");
                menu.add(new JMenuItem("item1", new Icon() {
                    public int getIconHeight() {
                        return 16;
                    }

                    public int getIconWidth() {
                        return 16;
                    }

                    public void paintIcon(Component c, Graphics g, int x, int y) {
                        Graphics2D g2 = (Graphics2D) g.create();
                        g2.setColor(Color.red);
                        g2.fillRect(x, y, 15, 15);
                        g2.dispose();
                    }
                }));
                menu.add(new JCheckBoxMenuItem("item2", new Icon() {
                    public int getIconHeight() {
                        return 8;
                    }

                    public int getIconWidth() {
                        return 8;
                    }

                    public void paintIcon(Component c, Graphics g, int x, int y) {
                        Graphics2D g2 = (Graphics2D) g.create();
                        g2.setColor(Color.red);
                        g2.fillRect(x, y, 7, 7);
                        g2.dispose();
                    }
                }));
                JRadioButtonMenuItem menuItem3 = new JRadioButtonMenuItem("item3");
                menuItem3.setSelected(true);
                menu.add(menuItem3);
                jmb.add(menu);

                this.setJMenuBar(jmb);

                this.setSize(200, 200);
                this.setLocationRelativeTo(null);
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }

            public static void main(String[] args) throws Exception {
                UIManager.setLookAndFeel(new MetalLookAndFeel());
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        new NewBugTest().setVisible(true);
                    }
                });
            }
        }
        =============Source end===============
        The description of a duplicate bug (6745220):

        FULL PRODUCT VERSION :
        Any version of Tiger and Mustang

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

        A DESCRIPTION OF THE PROBLEM :
        The menu accelerators under RTL layout are not aligned correctly.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Create an application with different menu items and set frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        The accelerator texts are not aligned and many of them are cur by the window itself. See many screenshots of Metal, Windows and third-party LAFs that inherit them at http://weblogs.java.net/blog/kirillcool/archive/2006/02/aligning_menu_i_1.html

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Accelerator texts are aligned
        ACTUAL -
        Accelerator texts are partlt cut and not aligned

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        As described in https://looks.dev.java.net/issues/show_bug.cgi?id=111 the line

         accOffset = maxValue - acceleratorRect.width;

        (613 in Tiger) should be replaced by

         accOffset = menuItem.getComponentOrientation().isLeftToRight()
             ? maxValue - acceleratorRect.width
             : acceleratorRect.width - maxValue;

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mlapshin Mikhail Lapshin (Inactive)
                  Reporter:
                  mlapshin Mikhail Lapshin (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: