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

There are problems sizing dialogs under win32

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      x86
    • OS:
      windows_95
    • Verification:
      Not verified

      Description

      In trying to port an app from JDK 1.0.1 to JDK 1.0.2, I found some
      serious problems in trying to size dialogs. I've used
      resize(preferredSize()) to try to size dialogs in the past, calling this
      after having added the panels and components I wanted. On JDK 1.0.1, this
      works fine. On JDK 1.0.2, it doesn't seem to work in most cases.

      The attached code illustrates it (on NT 4.0 Beta and Win95). To reproduce,
      compile and run the app (attached below), then use the File/Do Dialog menu
      item. The dialog comes up with the message text non-visible, since the
      window is too small. Resizing (manually) the window will show the message
      text. Adding the (supposedly redundant) call to resize(preferrredSize())
      afterthe call to pack() fixes this once (only) in an app I'm converting,
      doesn't seem to fix it here at all.

      The workaround seems to be to call resize(preferredSize()) *after* show()is
      called. However, this only works since JDK 1.0.2's dialogs are still not
      truly modal (see report #1255730). It also looks bad, since the dialog visibly
      alters shape (and components shuffle positions) when the dialog is first
      displayed.

      import java.awt.*;

      class MessageBox extends Dialog
      {
          Button okButton;

          protected void initialize(String msg)
          {
              setLayout(new BorderLayout());

              Panel p = new Panel();
              okButton = new Button("OK");
              p.add(okButton);
              add("South", p);

              add("Center", new Label(msg, Label.CENTER));

              //setResizable(false);

              pack();
              resize(preferredSize());
          }

          public boolean handleEvent(Event evt)
          {
              if (evt.id == Event.ACTION_EVENT && evt.target == okButton) {
                  hide();
                  dispose();
                  return true;
              } else {
                  return super.handleEvent(evt);
              }
          }

          public MessageBox(Frame parent, String title, String msg)
          {
              super(parent, title, true); // true ==> "modal"
              initialize(msg);
          }
      }

      class MenuFrame extends Frame
      {
          static String exitLabel = "E&xit\\tAlt+F4";

          MenuBar makeMenu()
          {
              MenuBar menuBar = new MenuBar();

              Menu fileMenu = new Menu("&File");
              fileMenu.add("&Do Dialog");
              fileMenu.addSeparator();
              fileMenu.add(exitLabel);
              menuBar.add(fileMenu);

              return menuBar;
          }

          public boolean handleEvent(Event evt)
          {
              if (evt.target instanceof MenuItem) {
                  //System.out.println("Menu item: " + evt.arg);
                  if (evt.arg.equals(exitLabel)) {
                      //hide();
                      //dispose();
                      System.exit(0);
                  }
                  doDialog();
                  return true;
              }
              if (evt.id == Event.WINDOW_DESTROY) {
                  //hide();
                  //dispose();
                  System.exit(0);
                  return true;
              }
              return super.handleEvent(evt);
          }

          public void doDialog()
          {
              new MessageBox(this, "A Modal Message Box", "See when the show()
      method returns!").show();
              System.out.println("MessageBox.show() returned");
          }

          public void open(String title)
          {
              setTitle(title);
              setMenuBar(makeMenu());
              resize(100,50);
              show();
          }
      }

      public class T34
      {
          public static void main(String args[])
          {
              new MenuFrame().open("Test Modal Dialog!");
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              tballsunw Tom Ball (Inactive)
              Reporter:
              tonywyant Tony Wyant (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: