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

JMenuItem inconsistency/i18n issue/L&F issue

XMLWordPrintable

    • beta2
    • generic
    • generic



      Name: moC74494 Date: 06/12/98


      We've run across another item in Swing that should get its default values from the L&F instead of the component.

      The issue is with JMenuItems. They hard-code the default relative positions of the text relative to the icons on the menu item to be horizontally JButton.LEFT. This choice is only true for left to right reading cultures, not right to left readers (Hebrew, Arabic).

      To make the behavior even more confusing, JMenuItems created through using the JMenu.add(Action) method _use different defaults_. The add(Action) method explicitly sets the relative positioning to be JButton.RIGHT.

      The L&F should be queried for the default positions, since this is a L&F wide issue that applies to all apps that use the same L&F.

      Swing 1.0.2:

      JMenuItem.java

      public JMenuItem(String text, Icon icon) {
        setModel(new DefaultButtonModel());
        init(text, icon);
        setBorderPainted(false);
        setFocusPainted(false);
        setHorizontalTextPosition(JButton.LEFT);
        setHorizontalAlignment(JButton.LEFT);
        updateUI();
      }

      JMenu.java

      public JMenuItem add(Action a) {
        JMenuItem mi = new JMenuItem((String)a.getValue(Action.NAME),
                                    (Icon)a.getValue(Action.SMALL_ICON));
        mi.setHorizontalTextPosition(JButton.RIGHT);
        mi.setVerticalTextPosition(JButton.CENTER);
        mi.setEnabled(a.isEnabled());
        mi.addActionListener(a);
        add(mi);
        PropertyChangeListener actionPropertyChangeListener =
           createActionChangeListener(mi); a.addPropertyChangeListener(actionPropertyChangeListener);
        return mi;
      }
      (Review ID: 33512)
      ======================================================================

            peterz Peter Zhelezniakov
            moanceasunw Mircea Oancea (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: