-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.0.2
-
sparc
-
solaris_2.5
-
Verified
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
> 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