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

Invoking TabelColumn.sizeWidthToFit() causes a NullPointerException

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.1.5, 1.2.0
    • Fix Version/s: 1.0.2
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      generic, x86
    • OS:
      generic, windows_nt
    • Verification:
      Not verified

      Description


      Invoking TabelColumn.sizeWidthToFit() causes a NullPointerException:
      java.lang.NullPointerException
              at java.awt.swing.table.TableColumn$1.getTableCellRendererComponent(TableColumn.java:624)
              at java.awt.swing.table.TableColumn.sizeWidthToFit(TableColumn.java:553)
              at TableTester.<init>(JTableTest.java:70)
              at JTableTest.main(JTableTest.java:17)


      Using JDK 1.2 ("J" build).

      The following application demonstrates this.

      =====================================================================
      /*
       * JTableTest.java
       * Invoking TableColumn.sizeWidthToFit() causes a NullPointerException
       *
       */

      import java.awt.BorderLayout;
      import java.awt.swing.*;
      import java.awt.swing.border.EmptyBorder;
      import java.awt.swing.table.*;

      public class JTableTest extends JFrame {

         public static void main( String[] argv ) {
            JFrame frame = new JFrame();

            frame.getContentPane().add(new TableTester());
            frame.pack();
            frame.setSize(400,350);
            frame.setVisible(true);
         }

         public void JTableTest() {
         }
      }

      class TableTester extends JPanel {
      JTable table = null;
      TableColumn tc = null;

      public TableTester() {
      setLayout(new BorderLayout());
      setBorder(new EmptyBorder(5,5,5,5));

      // Column headers
      final String[] headers = {"Name", "Capital City", "Language(s)",
      "Monetary Unit(s)", "EC Member"};

      // Table data
                final Object[][] data = {
                  {"Albania", "Tirane", "Albanian, Greek", "Lek", new Boolean(false)},
                  {"Andorra", "Andorra la Vella", "Catalan, French, Spanish", "French Franc, Spanish Peseta", new Boolean(false)},
                  {"Austria", "Vienna", "German, Slovenian, Croatian", "Schilling", new Boolean(false)},
                  {"Belarus", "Minsk", "Byelorussian, Russian", "Belarusian Rubel", new Boolean(false)},
                  {"Belgium", "Brussels", "French, Flemish, German", "Belgian Franc", new Boolean(true)},
      };

                TableModel dataModel = new AbstractTableModel() {
                  public int getColumnCount() { return headers.length; }
                  public int getRowCount() { return data.length;}
                  public Object getValueAt(int row, int col) {return data[row][col];}
                  public String getColumnName(int column) {return headers[column];}
                  public Class getColumnClass(int col) {
      return getValueAt(0,col).getClass();
      }
                  public void setValueAt(Object aValue, int row, int column) {
      System.out.println("Setting value to " + aValue);
      data[row][column] = aValue;
        }
      public boolean isCellEditable(int row, int col) {return (col==4);}
                };

                table = new JTable(dataModel);

                JScrollPane scrollpane = JTable.createScrollPaneForTable(table);
      add(scrollpane, BorderLayout.CENTER);

        // Invoking TableColumn.sizeWidthToFit() causes NPE
      System.out.println("** Invoking TableColumn.sizeWidthToFit()... ");
      table.getColumn(table.getColumnName(2)).sizeWidthToFit();
      }
      }
      =====================================================================
      Here is some more info:
      Found a bug in JFC 1.0.1 TableColumn.sizeWidthToFit(); In line 553 of TableColumn.java, a call is made to getTableCellRenderComponent.

      comp = this.getHeaderRenderer().getTableCellRendererComponent(null,
      getHeaderValue(), false, false, 0, 0);

      The call fails at line 624 since the null being passed into getTableCellRenderComponent instead of a valid table...

          protected TableCellRenderer createDefaultHeaderRenderer() {
      DefaultTableCellRenderer label = new DefaultTableCellRenderer() {
      public Component getTableCellRendererComponent(JTable table, Object value,
                               boolean isSelected, boolean hasFocus, int row, int column) {
      JTableHeader header = table.getTableHeader();


      ronan.mandel@Eng 1998-03-16

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              erapinsunw Eric Rapin (Inactive)
              Reporter:
              gaurisha Gauri Sharma (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: