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

setVisible(false) to a Frame will make the dialog box child invisiable also.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.2.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description

      When you set a dialog box's parent to invisible using setVisible(false), it also makes the dialog box associated with that parent invisible. This is probably not the expected behavior. The worse part is that when you attempt to make the dialog visible again it does not become visible. The following code
      shows this problem. I have tried it on jdk1.1.6, 1.1.7 and 1.2. And they
      all have the same problem. Please note, I am not sure if these two problems
      are considered two different bugs, or one is caused by another. Try this out when you get it running..

      1. Click the "Show" button and MyFrame shows.
      2. Click the "Dialog" button on MyFrame and the dialog shows.
      3. Now click the cancel button on MyFrame and watch MyFrame AND the dialog
      become invisible.
      (this is not as expected. The dialog should not be made invisible just
      because its parent
      was)
      4. Now click the "Show" button again on MainFrame and MyFrame shows.
      5. Now click the "Dialog" button and you will notice that the dialog FAILS
      to become
      visible. It is hopelessly lost.
       

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

      class Tpdlb {

         public static void main(String argv[]) {
            new MainFrame(new MyFrame());
         }
      }

      class MainFrame extends Frame implements ActionListener {

         MyFrame mMyFrame;

         MainFrame(MyFrame myFrame) {
            setLayout(new FlowLayout(FlowLayout.CENTER));
            setBounds(50,50,500,500);
            setTitle("Main Frame");
            mMyFrame = myFrame;
            Button showButton = new Button("Show");
            Button quitButton = new Button("Quit");
            showButton.addActionListener(this);
            quitButton.addActionListener(this);
            add(showButton);
            add(quitButton);
            setVisible(true);
         }

         public void actionPerformed(ActionEvent e) {
            if ( e.getActionCommand().equals("Show") ) {
               mMyFrame.setVisible(true);
            }
            else {
               System.exit(0);
            }
         }

      }

      class MyFrame extends Frame implements ActionListener {

         Dialog myDialog = new Dialog(this, "Test Dialog", false);

         MyFrame() {
            setLayout(new FlowLayout(FlowLayout.CENTER));
            setBounds(100,100,400,400);
            setTitle("My Frame");
            Button cancelButton = new Button("Cancel");
            Button dialogButton = new Button("Dialog");
            cancelButton.addActionListener(this);
            dialogButton.addActionListener(this);
            add(cancelButton);
            add(dialogButton);
            myDialog.setBounds(400,400,600,300);
         }

         public void actionPerformed(ActionEvent e) {
            if( e.getActionCommand().equals("Cancel") ) {
               setVisible(false);
            }
            else {
               myDialog.setVisible(true);
            }
         }

      }



        Attachments

          Activity

            People

            Assignee:
            son Oleg Sukhodolsky (Inactive)
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: