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

Static var set to null in JTable's windowClosing() handler (1.1.x only)

XMLWordPrintable

    • 1.2.2
    • x86
    • windows_nt



      Name: krT82822 Date: 07/02/99


      7/2/99 kevin.ryan@eng -- if you resize this JTable to be smaller than its initial size, then close the window (via the close box on the frame), you
      get NPE under JDK 1.1.8 and Swing 1.1.1 beta2. Problem does not occur under JDK 1.2.2 RC2.

      ----------------------------------
      For some reason, the static variable
      mainFrame gets set to null when the JTable draws all its columns.
      It doesn't happen when the table doesn't draw all the columns.
      Also doesn't occur on Java 1.2.

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.table.*;

      public class TestFrame {
         private static JFrame mainFrame;
         private static JTable content;
         
         public static void main(String[] args) {
            mainFrame = new JFrame("Test Frame");
              
            mainFrame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      doFoo();
                  System.exit(0);
                  }
              });
            
            content = new JTable(new TestFrameModel());
            
            mainFrame.getContentPane().add(content);
            mainFrame.pack();
            mainFrame.setLocation(0, 0);

            //Too big; causes NullPointerException when you close the frame
            Dimension d = new Dimension(1000, 750);
            
            //This line works until you resize the frame too much
            //Dimension d = new Dimension(400, 300);

            mainFrame.setSize(d);
            
            mainFrame.setVisible(true);
         }
         
         private static void doFoo() {
            System.out.println(mainFrame.getSize());
         }
         
         static class TestFrameModel extends AbstractTableModel {
            public int getColumnCount() {
               return 20;
            }

            public int getRowCount() {
               return 3000;
            }

            public Object getValueAt(int row, int column) {
               return column + ", " + row;
            }
         }
      }
      (Review ID: 85151)
      ======================================================================

            pmilnesunw Philip Milne (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: