Re: DefaultTableModel() is a crap / How to hide a Table column?

From: Owen Jacobson (ojacobson_at_example.com)
Date: 03/09/05


Date: Wed, 09 Mar 2005 20:13:48 GMT

On Sun, 06 Mar 2005 16:51:08 +0100, Mark Sizzler wrote:

> It all started with my search for a possibility to store data values in a JTable without displaying it.
> I read somewhere in the Sun docs that columns without a header are not displayed.
> Ok, I thought, according to a good coding style they are not displayed but they are stored.
> But what a crap, the data is even worse deleted. See the simplified scenario below:
>
> String rowData[][] = {
> { "firstrowfirstcol", "firstrowsecondcol" },
> { "secondrowfirstcol", "secondrowsecondcol" }
> };
>
> String columnNames[] = {
> "col1head"
> };
>
> DefaultTabelModel mytm = new DefaultTableModel(rowData, columnNames);
>
> After performing the last command not only mytm does not contain the values of the second column
> but also the values of the second column are removed from the rowData!!!
> What a poor system architecture. It costs me a half day to find it out because I could not believe it.
>
> Do I really have to setup a storage outside of DefaultTableModel to be able to store
> additional data ?
>
> Mark

That, or write your own implementation of TableModel. It's not hard; it
took me far less than half a day to write a simple one for an application
and gave me near-perfect control over what was displayed where in the
table.

Don't use GUI components to store data. Try using a TableModel as an
adaptor between your data storage and the GUI, rather than as data storage
itself.