Click to See Complete Forum and Search --> : JTable Constructor problems w/ ColumnModels


Jarreth
April 2nd, 1999, 04:19 PM
I think I may be missing something, and am hoping for help. I've tried this with both swing 1.1 and swing 1.1.1beta, and both have the same issue.

I've created a Table Model

public class TableAdapt extends AbstractTableModel
{ .... }

which I then use in my main program:

TableAdapt ta = new TableAdapt();
final JTable table = new JTable(ta);

This all works fine.

I've tried creating an extension of DefaultTableColumnModel and then using it in the JTable constructor:
final JTable table = new JTable(ta, myTableColumnModel);

This breaks. Everything runs, but none of the cell information is drawn, including column headers. No division lines -- just white space.

I checked the code of JTable. The constructors show that if parm 2 (tablecolumnmodel) is null, then it creates its own: new DefaultTableColumnModel();

I figured my table model might be at fault, so I tried this:
final JTable table = new JTable(ta, new DefaultTableColumnModel());

This breaks it in exactly the same way. I've even tried creating an actual instance of the DefaultTableColumnModel before using it in the JTable constructor.

Am I missing some behavior information somewhere? Is this a break/bug? I'd be happy to post code if needed, but anyone who's dealt with at least constructing from AbstractTableModel should be able to reproduce this.

Bogdan Matasaru
April 6th, 1999, 11:47 AM
If you do not call addColumn in your DefaultTableColumnModel derived class, there will be no columns to show. This is why you get the empty table.