Hello,
I am creating a JTable with a custom table model and a custom column model. However the table header is not being displayed (yes, it is in a JScrollPane). I've shrunk the problem down into a single compileable example:
Thanks for your help.
import javax.swing.*;
import javax.swing.table.*;
public class Test1 extends JFrame
{
public static void main(String args[])
{
JTable table;
TableColumnModel colModel=createTestColumnModel();
TestTableModel tableModel=new TestTableModel();
Test1 frame=new Test1();
table=new JTable(tableModel, colModel);
frame.getContentPane().add(new JScrollPane(table));
frame.setSize(200,200);
frame.setVisible(true);
}
private static DefaultTableColumnModel createTestColumnModel()
{
DefaultTableColumnModel columnModel=new DefaultTableColumnModel();
columnModel.addColumn(new TableColumn(0));
return columnModel;
}
static class TestTableModel extends AbstractTableModel
{
public int getColumnCount()
{
return 1;
}
public Class<?> getColumnClass(int columnIndex)
{
return String.class;
}
public String getColumnName(int column)
{
return "col";
}
public int getRowCount()
{
return 1;
}
public Object getValueAt(int row, int col)
{
return "test";
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
{
}
}
}
Edited by: 802416 on 14-Oct-2010 04:29
added