Re: DefaultTableModel() is a crap / How to hide a Table column?
From: David (nodeo_at_sk.sympatico.ca)
Date: 03/06/05
- Next message: SPG: "Re: Alpha colours using 1.1 AWT JDK?"
- Previous message: Nomak: "Graphic JavaBean"
- Next in thread: Rhino: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Maybe reply: Rhino: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Maybe reply: John: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Maybe reply: Owen Jacobson: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 6 Mar 2005 11:05:02 -0600
"Mark Sizzler" <marksiz@email.org> wrote in message
news:d0f8tb$mmk$04$1@news.t-online.com...
> 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 ?
Take a look at AbstractTableModel in the Java API. You can create your
own TableModel and use it in place of the default one in the JTable.
Use an inner class or something.
private class FileTableModel extends AbstractTableModel {
// make a vector or something for storage of data and
// column names ect.
// // overide these minimum
public int getRowCount();
public int getColumnCount();
public Object getValueAt(int row, int column);
}
The table calls the above methods when it's filling itself up
for display.
You can overide getColumnCount() to return one (or more) less
than the amount of actual data columns, and that's all that will
show.
Make a getValueAt(int row, int column) method to return the
appropriate values, which the table will then display.
You can add alternative methods for your own use to return
the values which the table doesn't display ect.
It's kind of neat, and not too complicated if your table is
not too involved. You have to fiddle a bit with the column
name arrays (or vector) and methods as well if I remember
right, so that appropriate values will be returned for specific
columns.
David Otte
>
> Mark
>
- Next message: SPG: "Re: Alpha colours using 1.1 AWT JDK?"
- Previous message: Nomak: "Graphic JavaBean"
- Next in thread: Rhino: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Maybe reply: Rhino: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Maybe reply: John: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Maybe reply: Owen Jacobson: "Re: DefaultTableModel() is a crap / How to hide a Table column?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|