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

Modal dialogs which were launched by JButton cause NULLPointerException.

XMLWordPrintable

    • x86, sparc
    • solaris_2.5.1, solaris_2.6, windows_nt

      Modal dialogs which were launched by JButton cause NULLPointerException error when it is closed by setVisible(false)

      As a result of setVisible(false), dialogs disappear but cause an Exception error as follows:

      java.lang.NullPointerException at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1416)
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1329)
              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1264)
              at java.awt.Container.dispatchEventImpl(Container.java:824)
              at java.awt.Window.dispatchEventImpl(Window.java:401)
              at java.awt.Component.dispatchEvent(Component.java:1393)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)
       
      Here is test-code that causes exception.

      // test-code
      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;

      public class DialogWindow extends JFrame implements ActionListener{
          private AboutFrame dialog;

          public DialogWindow() {
              super("test");

      //**** if Button is used then no exception under solaris ****//
              JButton button = new JButton("Click to bring up dialog");
              button.addActionListener(this);
              add(button);
              addWindowListener(wl);
          }

          WindowListener wl = new WindowAdapter(){
              public void windowClosing(WindowEvent event){
                  System.exit(0);
              }
          };


          public void actionPerformed(ActionEvent event) {
              if(dialog == null) dialog = new AboutFrame(this);
              dialog.setVisible(true);
          }

          public static void main(String args[]) {
              DialogWindow window = new DialogWindow();

              window.pack();
              window.setVisible(true);
          }
      }


      class AboutFrame extends Dialog implements ActionListener
      {
          JPanel upperPanel;
          JPanel lowerPanel;

          public AboutFrame(JFrame frame){
              super(frame, "Cool AWT Test Team!!!", true);
              setSize(300,200);

              upperPanel = new JPanel(true);
              lowerPanel = new JPanel(true);
              lowerPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

              JButton ok = new JButton("OK");
              ok.setActionCommand("OK");
              ok.addActionListener(this);

              lowerPanel.add(ok);

              add("Center", upperPanel);
              add("South", lowerPanel);
          }

          public void actionPerformed(ActionEvent e){
              if((e.getActionCommand()).equals("OK")){
                  setVisible(false); // cause exception.
              }
         }

      }
       
      // The end of the test-code.

      bae-chul.kim@Eng 1997-06-25

            jeff Jeff Dinkins
            bkimsunw Bae-chul Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: