Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Horizontal columns in a JTable?

519 views
Skip to first unread message
Message has been deleted
Message has been deleted

John B. Matthews

unread,
May 29, 2013, 3:57:26 PM5/29/13
to
In article <JTable-201...@ram.dialup.fu-berlin.de>,
r...@zedat.fu-berlin.de (Stefan Ram) wrote:

> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> Is there a way to have horizontal columns with a JTable (and
>> vertical rows)? (Where a column is defined as that vector
>> whose components all have the same type.)
>>
>> Instead of
>>
>> Name Value
>> 01 A 1.2
>> 02 B 2.3
>> 03 C 0.9
>>
>> , I want the same table model to be rendered as
>>
>> 01 02 03
>> Name A B C
>> Value 1.2 2.3 0.9

JTable displays what the TableModel returns for getValueAt();
you will have to transpose the model.

> Equivalent question: I want to set a row type for all the values
> in a row, while values in a column might have mixed types.

You can recycle the default cell renderer(s), as shown here:

<http://stackoverflow.com/a/7701420/230513>

> The standard solution would be to write a new TableUI for this
> I guess, that renders columns horizontally. I'd like to know
> if there is a shortcut.

You can recycle the default header renderer, as shown here:

<http://stackoverflow.com/a/8005006/230513>

The result is still a JTable, i.e. it has a TableColumnModel,
not a notional RowColumnModel.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Roedy Green

unread,
May 30, 2013, 10:34:29 PM5/30/13
to
On 29 May 2013 12:47:34 GMT, r...@zedat.fu-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

> Is there a way to have horizontal columns with a JTable (and
> vertical rows)?

You have a table model that uses a row, column to fetch the data.
getValue is a function that can store the data internally in any way
it pleases. In theory, it does not even need to store data. It could
compute it on the fly.

--
Roedy Green Canadian Mind Products http://mindprod.com
Getting information off the Internet is
like taking a drink from a fire hydrant.
~ Mitch Kapor 1950-11-01
0 new messages