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

There are problems sizing dialogs under win32


    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:
    • Verification:
      Not verified


      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

      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");
              add("South", p);

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



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

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

      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");

              return menuBar;

          public boolean handleEvent(Event evt)
              if (evt.target instanceof MenuItem) {
                  //System.out.println("Menu item: " + evt.arg);
                  if (evt.arg.equals(exitLabel)) {
                  return true;
              if (evt.id == Event.WINDOW_DESTROY) {
                  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)

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




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


              • Created: