Article View: borland.public.jbuilder.java.swing
Article #11342JTable Columns
From: Quach Hoa Thanh
Date: Sun, 13 Jun 1999 00:00
Date: Sun, 13 Jun 1999 00:00
74 lines
2634 bytes
2634 bytes
Hi everybody, I'm using JBuilder 3 and produce the code below:
public class TableDialog extends JDialog
{
// The line below (DefaultTableModel) causes a run-time error in
JBuilder 3 but not in JBuilder 2
//DefaultTableModel model = new DefaultTableModel()
// The line below (AbstractTableModel) works out beautifully
AbstractTableModel model = new AbstractTableModel()
{
Object[][] data = { {"Bank Account",Boolean.FALSE,"0"},
{"Credit Card Owed",Boolean.FALSE,"20000"},
{"Car Loan",Boolean.TRUE,"10000.00"},
{"Tax",Boolean.FALSE,"4000.00"},
{"Total",Boolean.TRUE,"34000.00"}
};
// For some reasons, I didn't see the three columns title at all.
String[] columnNames = {"Bank's Money","YES","Amount"};
public int getRowCount()
{
return data.length;
}
public int getColumnCount()
{
return data[0].length;
}
public Object getValueAt(int row, int col)
{
return data[row][col];
}
public void setValueAt(Object value, int rowIndex, int columnIndex)
{
if (value instanceof Boolean && columnIndex == 1)
{
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex,columnIndex);
}
}
public boolean isCellEditable(int rowIndex, int columnIndex)
{
return columnIndex == 1;
}
public String getColumnName(int columnIndex)
{
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex)
{
return data[0][columnIndex].getClass();
}
};
I have two problems with the above code and I still don't know why.
1. JTable displays values in the cell from the two dimensional array.
But it didn't show any columns title at all even though the code tells
it to do so.
2. DefaultTableModel is a subclass of AbstractTableModel. For some
reasons, it blows up when I try to use it. AbstractTableModel works out
beautifully.
Thanks for all your helps.
Thanh
Technical Details
Message-ID:
<3763E235.80724A4@ns.sympatico.ca>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,eb4b6527d333ff79,start X-Google-Attributes: gid111d45,public From: Quach Hoa Thanh <thq.qua@ns.sympatico.ca> Subject: JTable Columns Date: 1999/06/13 Message-ID: <3763E235.80724A4@ns.sympatico.ca> X-Deja-AN: 489132271 Content-Transfer-Encoding: 7bit Organization: Self Employed Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Reply-To: thq.qua@ns.sympatico.ca Newsgroups: borland.public.jbuilder.java.swing