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

AWT: Unexpected MenuBar width and frame overlap

XMLWordPrintable

    • x86
    • windows

      SYNOPSIS
      --------
      AWT: Unexpected MenuBar width and frame overlap

      OPERATING SYSTEM
      ----------------
      Windows only

      FULL JDK VERSION
      ----------------
      All (JDK 7, 6, 5.0 and 1.4.2)
      Including JDK 7 b142

      PROBLEM DESCRIPTION
      -------------------
      If the frame size is smaller than a MenuBar's width, the MenuBar overlaps the edge of the frame and seems to be highlighted incorrectly when it has the focus.

      STEPS TO REPRODUCE
      ------------------
      1. Compile and run the test program MenuBarTest1
      2. Press F10, or click on the MenuBar, to move focus to the MenuBar.
      3. Observe two related issues:
           b) The far right of the MenuBar overlaps the edge of the frame
           a) MenuBar is highlighted, but the overlapping section on the far
              right remains un-highlighted.

      The Swing test (MenuBarTestSwing) can be used to observe the correct behaviour.

      TESTCASE
      --------

      AWT test (behaves incorrectly)

      import java.awt.*;
      import java.awt.event.*;

      class MenuBarTest1 extends Frame {
          MenuBarTest1 () {
              setTitle("MenuBarTest1");
              MenuBar menubar= new MenuBar();
              Menu menu = menubar.add(new Menu("mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"));
              setMenuBar(menubar);
              setSize(100, 50);
              addWindowListener(new WindowAdapter() {
                                    public void windowClosing(WindowEvent e) { System.exit(0);}
                                });
              setLocationRelativeTo(null);
              setVisible(true);
          }
          public static void main(String[] args) {
              new MenuBarTest1();
          }
      }

      Equivalent test with Swing (behaves correctly):

      import javax.swing.*;
      import java.awt.event.*;

      class MenuBarTestSwing extends JFrame {
          MenuBarTestSwing () {
              setTitle("MenuBarTest1");
              JMenuBar menubar= new JMenuBar();
              JMenu menu = menubar.add(new JMenu("mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"));
              setJMenuBar(menubar);
              setSize(100, 50);
              addWindowListener(new WindowAdapter() {
                                    public void windowClosing(WindowEvent e) { System.exit(0);}
                                });
              setLocationRelativeTo(null);
              setVisible(true);
          }
          public static void main(String[] args) {
              new MenuBarTestSwing();
          }
      }

            bagiras Oleg Pekhovskiy (Inactive)
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: