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

Initial ICONIFIED state makes Frame shown and then minimized

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2.2
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description

      If a Frame calls setState(Frame.ICONIFIED) before calling setVisible(true), the Frame should be shown in ICONIFIED state. Instead, it is now shown in normal state and then iconified.

      mike.colburn@East 1999-01-25
      Test:

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

      class FrameStateTest extends Frame implements ActionListener, ItemListener {

          Button btnCreate = new Button("Create Frame");
          Button btnDispose = new Button("Dispose Frame");
          CheckboxGroup cbgState = new CheckboxGroup();
          CheckboxGroup cbgResize = new CheckboxGroup();
          Checkbox cbIconState = new Checkbox("Frame state ICONIFIED",cbgState,false);
          Checkbox cbNormState = new Checkbox("Frame state NORMAL",cbgState,true);
          Checkbox cbNonResize = new Checkbox("Frame Nonresizable",cbgResize,false);
          Checkbox cbResize = new Checkbox("Frame Resizable",cbgResize,true);
          int iState = 0;
          boolean bResize = true;
          CreateFrame icontst;

          FrameStateTest() {
              super("Frame State Test");
              
              btnDispose.setEnabled(false);
              add(btnCreate, BorderLayout.NORTH);
              add(btnDispose, BorderLayout.SOUTH);

      Panel p = new Panel(new GridLayout(0,1));
      p.add(cbIconState);
      p.add(cbResize);
      add(p, BorderLayout.WEST);

      p = new Panel(new GridLayout(0,1));
      p.add(cbNormState);
      p.add(cbNonResize);
      add(p, BorderLayout.EAST);

              // Add Listeners
              btnDispose.addActionListener(this);
              btnCreate.addActionListener(this);
              cbNormState.addItemListener(this);
              cbResize.addItemListener(this);
              cbIconState.addItemListener(this);
              cbNonResize.addItemListener(this);
              this.addWindowListener(new WindowEventHandler());

              setSize(400, 200);
              show();
          }

          public void actionPerformed(ActionEvent evt) {
          
          
              if (evt.getSource() == btnCreate) {
                  btnCreate.setEnabled(false);
                  btnDispose.setEnabled(true);
                  icontst = new CreateFrame(iState, bResize);
                  icontst.show();
              } else if (evt.getSource() == btnDispose) {
                  btnCreate.setEnabled(true);
                  btnDispose.setEnabled(false);
                  icontst.dispose();
              }
          }

          public void itemStateChanged(ItemEvent evt) {
          
           if (cbNormState.getState()) iState = 0;
           if (cbIconState.getState()) iState = 1;
           if (cbResize.getState()) bResize = true;
           if (cbNonResize.getState()) bResize = false;
          
          }
          
          class WindowEventHandler extends WindowAdapter {
              public void windowClosing(WindowEvent evt) {
                  dispose();
              }
          }
                  
          static public void main(String[] args) {
              new FrameStateTest();
          }
      }


      class CreateFrame extends Frame implements ActionListener, WindowListener {
          
        static int e=0;
        static int u=0;
        static int p=0;
        static int i=0;
        static int v=0;
        Button b1, b2, b3, b4, b5, b6, b7;
        boolean resizable = true;
        boolean iconic = false;
        String name = "Frame State Test";
          
        CreateFrame (int iFrameState, boolean bFrameResizable) {
        
          setTitle("Frame State Test (Window 2)");
         
          if (iFrameState == 1) {
      iconic = true;
          }
          
          if (!(bFrameResizable)) {
      resizable = false;
          }
              
          System.out.println("CREATING FRAME - Initially "+
      ((iconic) ? "ICONIFIED" : "NORMAL (NON-ICONIFIED)") + " and " +
      ((resizable) ? "RESIZABLE" : "NON-RESIZABLE") );
          
          setLayout(new FlowLayout() );
          b1 = new Button("resizable");
          add(b1);
          b2 = new Button("resize");
          add(b2);
          b3 = new Button("iconify");
          add(b3);
          b4 = new Button("iconify and restore");
          add(b4);
          b5 = new Button("hide and show");
          add(b5);
          b6 = new Button("hide, iconify and show");
          add(b6);
          b7 = new Button("hide, iconify, show, and restore");
          add(b7);
          b1.addActionListener(this);
          b2.addActionListener(this);
          b3.addActionListener(this);
          b4.addActionListener(this);
          b5.addActionListener(this);
          b6.addActionListener(this);
          b7.addActionListener(this);
          addWindowListener(this);
          
          setBounds(100,2,200, 200);
          setState(iconic ? Frame.ICONIFIED: Frame.NORMAL);
          setResizable(resizable);
          pack();
          setVisible(true);
          
          
        }

        public void actionPerformed ( ActionEvent e )
        {
          if ( e.getSource() == b2 ) {
      Rectangle r = this.getBounds();
      r.width += 10;
      System.out.println(" - button pressed - setting bounds on Frame to: "+r);
      setBounds(r);
      validate();
          } else if ( e.getSource() == b1 ) {
      resizable = !resizable;
      System.out.println(" - button pressed - setting Resizable to: "+resizable);
      ((Frame)(b1.getParent())).setResizable(resizable);
          } else if ( e.getSource() == b3 ) {
      System.out.println(" - button pressed - setting Iconic: ");
      dolog();
      ((Frame)(b1.getParent())).setState(Frame.ICONIFIED);
      dolog();
          } else if ( e.getSource() == b4 ) {
      System.out.println(" - button pressed - setting Iconic: ");
      dolog();
      ((Frame)(b1.getParent())).setState(Frame.ICONIFIED);
      dolog();
      try {
              Thread.sleep(1000);
      } catch (Exception ex) {};
      System.out.println(" - now restoring: ");
      ((Frame)(b1.getParent())).setState(Frame.NORMAL);
      dolog();
          } else if ( e.getSource() == b5 ) {
      System.out.println(" - button pressed - hiding : ");
      dolog();
      ((Frame)(b1.getParent())).setVisible(false);
      dolog();
      try {
              Thread.sleep(1000);
      } catch (Exception ex) {};
      System.out.println(" - now reshowing: ");
      ((Frame)(b1.getParent())).setVisible(true);
      dolog();
          } else if ( e.getSource() == b6 ) {
      System.out.println(" - button pressed - hiding : ");
      dolog();
      ((Frame)(b1.getParent())).setVisible(false);
      dolog();
      try {
              Thread.sleep(1000);
      } catch (Exception ex) {};
      System.out.println(" - setting Iconic: ");
      dolog();
      ((Frame)(b1.getParent())).setState(Frame.ICONIFIED);
      try {
              Thread.sleep(1000);
      } catch (Exception ex) {};
      System.out.println(" - now reshowing: ");
      ((Frame)(b1.getParent())).setVisible(true);
      dolog();
          } else if ( e.getSource() == b7 ) {
      System.out.println(" - button pressed - hiding : ");
      dolog();
      ((Frame)(b1.getParent())).setVisible(false);
      dolog();
      try {
              Thread.sleep(1000);
      } catch (Exception ex) {};
      System.out.println(" - setting Iconic: ");
      dolog();
      ((Frame)(b1.getParent())).setState(Frame.ICONIFIED);
      try {
              Thread.sleep(1000);
      } catch (Exception ex) {};
      System.out.println(" - now reshowing: ");
      ((Frame)(b1.getParent())).setVisible(true);
      dolog();
      try {
              Thread.sleep(1000);
      } catch (Exception ex) {};
      System.out.println(" - now restoring: ");
      ((Frame)(b1.getParent())).setState(Frame.NORMAL);
      dolog();
          }
        }
          
          public void windowActivated(WindowEvent e) {
              System.out.println(name + " Activated");
      dolog();
          }
          public void windowClosed(WindowEvent e) {
              System.out.println(name + " Closed");
      dolog();
          }
          public void windowClosing(WindowEvent e) {
              ((Window)(e.getSource())).dispose();
              System.out.println(name + " Closing");
      dolog();
          }
          public void windowDeactivated(WindowEvent e) {
              System.out.println(name + " Deactivated");
      dolog();
          }
          public void windowDeiconified(WindowEvent e) {
              System.out.println(name + " Deiconified");
      dolog();
          }
          public void windowIconified(WindowEvent e) {
              System.out.println(name + " Iconified");
      dolog();
          }
          public void windowOpened(WindowEvent e) {
              System.out.println(name + " Opened");
      dolog();
          }

          public void dolog() {
      System.out.println(" getState returns: "+getState());
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              herrick Andy Herrick
              Reporter:
              xdengsunw Xianfa Deng (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: