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

Constructor JTable(TableModel dm,TableColumnModel cm) doesn't work correctly.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.2.0
    • Fix Version/s: 1.0.2
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description

      The following commnet is from one of our customers :

      > If you pass a TableColumnModel in the constructor to a JTable, along
      > with
      > the TableModel, the TableColumnModel's values are not used. Worse
      > still,
      > is the data in the TableColumnModel is destroyed. This is because the
      > JTable
      > defaults to:
      >
      > setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
      > setAutoCreateColumnsFromModel(true);
      >
      > which destroys my TableColumnModel passed in the constructor.
      >
      > Mike Foley

      I have verified it with swing-1.0 and provided the following test which can demostrate this bug :

      import com.sun.java.swing.*;
      import com.sun.java.swing.table.*;

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

      public class ColTest extends JPanel {

        JTable table;

        public static void main(String[] args)
        {
          JFrame frame = new JFrame("test") ;
          frame.getContentPane().setLayout(new BorderLayout()) ;
          ColTest panel = new ColTest() ;
          frame.getContentPane().add("Center",panel) ;
          frame.setBounds(0,0,640,480) ;
          frame.setVisible(true) ;
        }


        public ColTest() {
          super();
          setLayout(new BorderLayout());

          // final
          final String[] names = {"First Name", "Last Name", "Favorite Color",
                                      "Favorite Sport", "Vegetarian"};

          // Create the dummy data (a few rows of names)
          final Object[][] data = {
          {"Mark", "Andrews", "red", "Baseball", new Boolean(true)},
          {"Tom", "Ball", "Blue", "Football", new Boolean(false)}
          };

          // Create a model of the data.
          TableModel dataModel = new AbstractTableModel() {
             public int getColumnCount() { return names.length; }
             public int getRowCount() { return data.length;}
             public Object getValueAt(int row, int col) {return data[row][col];}
             public String getColumnName(int column) {return names[column];}
          };
          TableColumnModel colModel = new DefaultTableColumnModel();
          colModel.setColumnMargin(100);
          System.out.println("setColumnMargin(100) before calling JTable(TableModel,
      TableColumnModel)");

          table = new JTable(dataModel, colModel) ;

          System.out.println("After constructing JTable : getColumnMargin = " + table
      .getColumnModel().getColumnMargin());


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

      patience.chu@Eng 1998-02-23

        Attachments

          Activity

            People

            Assignee:
            erapinsunw Eric Rapin (Inactive)
            Reporter:
            pchusunw Patience Chu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: