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

Inability to correctly size Frame with MenuBar and no components

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.3
    • client-libs
    • None
    • x86
    • windows_95



      Name: rlT66838 Date: 08/19/97


      import java.awt.*;

      /**
       * Reproduce awt bug. Running with no command line args
       * will show an improper layout. Running with one or more
       * args of any value will exclude the MenuBar, and the
       * layout is correct.
       *
       * We are attempting to set the height of a Frame with a
       * MenuBar and NO COMPONENTS, to be used for a main menu.
       * We can easily hard code the height, but this is not
       ( portable. ALL ATTEMPTS AT DETERMINING THE CORRECT HEIGHT
       * HAVE FAILED DUE TO AWT BUGS. Frame.getInsets().top
       * is useless, because frame.setSize(height, width) fails
       * to have the desired effect.
       *
       * We suspect the bug show below is related to our inability
       * to set a main menu frame height in a portable manner.
       * The following should work but doesn't:
       *
       * frame.pack();
       * // Height should be insets.top + titlebar.height
       * int height = frame.getInsets().top + frame.getSize().height;
       * frame.setSize(mainMenuWidth, height);
       *
       * @author Jack Harich
       */
      public class TestFrame {

      //---------- Initialization ------------------------------
      public static void main(String args[]) {
          new TestFrame(args);
      }
      public TestFrame(String args[]) {
          // Prepare frame
          Frame frame = new Frame("Test Frame");

          // Prepare MenuBar
          if (args.length > 0) {
              MenuBar menuBar = new MenuBar();
              frame.setMenuBar(menuBar);
              Menu fileMenu = new Menu("File");
              fileMenu.add(new MenuItem("Test 1"));
              menuBar.add(fileMenu);
          }

          // Button
          Button button = new Button("Test");
          frame.add("South", button);
          frame.pack();

          // Done
          frame.setVisible(true);
      }


      } // End class

      ======================================================================

            cchongsunw Creighton Chong (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: