Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fwd: JTable query!]
- From: terry.williams@xxxxxxxxxxxxx (Terry Williams)
- Subject: [Fwd: JTable query!]
- Date: Tue, 30 Nov 1999 10:28:52 +0000
This is a multi-part message in MIME format.
--------------7263344EE449D8848C6C6EA3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
if you want more than the default behaviour of the DefaultTableModel
I'm afraid you'll have to create your own TableModel. Not as hard as it
seems,
Here's a basic sample
public ReadOnlyTableModel extends AbstractTableModel
{
// stuff here that initialises columnNames & data
public boolean isCellEditable(int row, int col) { return false; }
public Class getColumnClass(int c) { return getValueAt(0, c);
public Object getValueAt(int row, int col)
{
return data[row][col];
// or however you've stored your info if its a Vector of Vectors
it maybe something like this
// Vector rowVec = (Vector)data.elementAt(row);
// return rowVec.elementAt(col);
}
public int getRowCount() { return data.length; } // or data.size if
using vector of vectors
public getColumnCount() { return columnNames.size(); }
public getColumnName(int col) { return columnNames[col]; }
}
I think that's all that is needed for an AbstractTableModel, I'm sure
someone will correct me if I'm wrong.
This may seem complex for such a small change but the DefaultTableModel
is
a very simplistic model with little flexibility, the flexibility comes
from being able to plug in your own table model - see the Swing
documentation (and Tutorial) for a more in depth discussion of
AbstractTableModel.
BTW all swing components have detault "something" models associated with
them, if you write you own versions then you can begin to appreciate the
full power of swing. I get a little tired of people telling me that
swing
is useless and inflexible - you only get out of it what you put into it!
Terry
--------------7263344EE449D8848C6C6EA3
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
X-Mozilla-Status2: 00000000
Message-ID: <3843A661.E5A212C6@xxxxxxxxxxxxx>
Date: Tue, 30 Nov 1999 10:26:41 +0000
From: Terry Williams <terry.williams@xxxxxxxxxxxxx>
Organization: WebTrak Ltd
X-Mailer: Mozilla 4.7 [en] (X11; I; SunOS 5.6 sun4u)
X-Accept-Language: en
MIME-Version: 1.0
To: Kakoli <kakoli@xxxxxxxxxxxx>
Subject: Re: JTable query!
References: <38439DF1.9FA76B7B@xxxxxxxxxxxx>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Kakoli wrote:
> I am creating a JTable with DefaultTableModel and I am setting data
> through setDataVector. Then how can I make the table non-editable so
> that user cannot edit any cell in the table. There is a method
> isCellEditable which returns whether a cell is editable/not. But how do
> I set a cell to non-editable mode?
> Thanking in advance,
> Kakoli
>
> ---
> To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
> To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
Hi,
if you want more than the default behaviour of the DefaultTableModel
I'm afraid you'll have to create your own TableModel. Not as hard as it
seems,
Here's a basic sample
public ReadOnlyTableModel extends AbstractTableModel
{
// stuff here that initialises columnNames & data
public boolean isCellEditable(int row, int col) { return false; }
public Class getColumnClass(int c) { return getValueAt(0, c);
public Object getValueAt(int row, int col)
{
return data[row][col];
// or however you've stored your info if its a Vector of Vectors
it maybe something like this
// Vector rowVec = (Vector)data.elementAt(row);
// return rowVec.elementAt(col);
}
public int getRowCount() { return data.length; } // or data.size if
using vector of vectors
public getColumnCount() { return columnNames.size(); }
public getColumnName(int col) { return columnNames[col]; }
}
I think that's all that is needed for an AbstractTableModel, I'm sure
someone will correct me if I'm wrong.
This may seem complex for such a small change but the DefaultTableModel is
a very simplistic model with little flexibility, the flexibility comes
from being able to plug in your own table model - see the Swing
documentation (and Tutorial) for a more in depth discussion of
AbstractTableModel.
BTW all swing components have detault "something" models associated with
them, if you write you own versions then you can begin to appreciate the
full power of swing. I get a little tired of people telling me that swing
is useless and inflexible - you only get out of it what you put into it!
--------------7263344EE449D8848C6C6EA3--
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Prev by Date: JTable query!
- Next by Date: Swing
- Previous by thread: JTable query!
- Next by thread: [Fwd: JTable query!]
- Index(es):