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

Dialog not shown when requested

XMLWordPrintable

    • 1.0beta2
    • sparc
    • solaris_2.5
    • Not verified

      I don't really believe this one myself ... it's too simple to be true!

      Attached is a test program. It is stripped down from something
      a lot bigger, and was really intended to show problems with GridBagConstraints.

      Instead, it shows a simpler problem: the Dialog does not paint on the screen
      when told to do so.

      However, the dialog believes it is visible, The following lines are the crux of
      the code ....

      // for a Dialog d ...

      System.out.println(d);
      d.show();
      System.out.println(d);
      System.out.println(d.getPeer());


      They produce the output

      java -cs Main
      HelpAboutDialog[45,16,130x180,hidden,layout=java.awt.GridBagLayout,modeless,title=HelpAboutDialog]
      HelpAboutDialog[45,16,130x180,layout=java.awt.GridBagLayout,modeless,title=HelpAboutDialog]
      sun.awt.motif.MDialogPeer[HelpAboutDialog[45,16,130x180,layout=java.awt.GridBagLayout,modeless,title=HelpAboutDialog]]


      which shows that the dialog has a sensible place, a sensible size, was hidden before
      the call to show and is not hidden after the call to show., and has a peer.
      The only problem is ... it is not showing on my screen!

      xwininfo does not indicate the presence of a child of my frame in X land either.

      The program was tested with
      /usr/local/java/NIGHTLY/1.0betaM-3/bin/java

      The program is .........
      --------------------------------------------
      import java.awt.Canvas;
      import java.awt.Color;
      import java.awt.Dialog;
      import java.awt.Dimension;
      import java.awt.Event;
      import java.awt.Frame;
      import java.awt.Graphics;
      import java.awt.GridBagConstraints;
      import java.awt.GridBagLayout;
      import java.awt.Menu;
      import java.awt.MenuBar;
      import java.awt.MenuItem;
      import java.awt.Rectangle;


      public class Main extends Frame
      {
        public static void main(String [] args) {
          new Main().show();
        }
          
        Main() {
          MenuBar mb = new MenuBar();
          Menu helpMenu = new Menu("Help");
          helpMenu.add(new HelpAbout(this));
          mb.add(helpMenu);
          mb.setHelpMenu(helpMenu);
          setMenuBar(mb);
          add("Center", new DemoCanvas(200, 100, Color.yellow));
          pack();
        }
      }

      class HelpAbout extends MenuItem
      {
        public HelpAbout(Frame parent) {
          super("About");
          this.parent = parent;
        }

        public void postEvent(Event evt) {
          if (evt.id == Event.ACTION_EVENT && getLabel().equals(evt.arg)) {
            Dialog d = new HelpAboutDialog(parent);
            Dimension s = d.size();
            Rectangle b = parent.bounds();
            d.move(b.x + (b.width - s.width)/2, b.y + (b.height - s.height)/2);
      System.out.println(d);
            d.show();
      System.out.println(d);
      System.out.println(d.getPeer());
          }
        }

        private Frame parent;
      }


      class HelpAboutDialog extends Dialog
      {
        HelpAboutDialog(Frame parent) {
          super(parent, "HelpAboutDialog", false);
          setResizable(false);
          GridBagLayout gbl = new GridBagLayout();
          GridBagConstraints c = new GridBagConstraints();
          setLayout(gbl);
          c.gridwidth = GridBagConstraints.REMAINDER;
          c.anchor = GridBagConstraints.CENTER;
          c.insets.top = c.insets.bottom = c.insets.left = c.insets.right = 10;

          Color[] colors = {Color.red, Color.green, Color.blue};

          for (int i = 0; i < colors.length; i++) {
            DemoCanvas dc = new DemoCanvas(100, 30, colors[i]);
            gbl.setConstraints(dc, c);
            add(dc);
          }

          pack();
        }

        public boolean handleEvent(Event evt) {
          switch (evt.id) {
          case Event.WINDOW_DESTROY:
            dispose();
            return true;
          }

          return false;
        }
      }


      class DemoCanvas extends Canvas
      {
        DemoCanvas(int w, int h, Color c) {

          this.c = c;
          d = new Dimension(w, h);
        }

        public void paint(Graphics g) {
          Dimension s = size();
          g.setColor(c);
          g.drawLine(0, 0, s.width, s.height);
          g.drawLine(s.width, 0, 0, s.height);
          g.drawRect(0, 0, s.width-1, s.height-1);
        }

        public Dimension minimumSize() { return d; }
        public Dimension preferredSize() { return d; }

        Color c;
        Dimension d;
      }

            sshaiosunw Sami Shaio (Inactive)
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: