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

JTable.addColumn and RowSorter.setSortKeys

101 views
Skip to first unread message

Thomas Lehmann

unread,
Jul 16, 2012, 6:24:20 AM7/16/12
to
You might wonder how this relates (title)...

When using "addColumn" on a table instance the model will be not adjusted to it; this means that "model.getColumnCount()" is zero but table.getColumnCount() is > 0.

My problem now is a simple row sorter (taken from Java Tutorial page) which
asks the model for the number of columns...

What I did - it's working so far - is:

model.setColumnCount(table.getColumnCount());

Is this the recommended solution? (I believe not)

Please, could somebody provide help?

Thanks,
Thomas

S.van Heek

unread,
Jul 17, 2012, 1:44:43 PM7/17/12
to
Am Montag, 16. Juli 2012 12:24:20 UTC+2 schrieb Thomas Lehmann:
> You might wonder how this relates (title)...
>
> When using "addColumn" on a table instance the model will be not adjusted to it; this means that "model.getColumnCount()" is zero but table.getColumnCount() is > 0.
>
> My problem now is a simple row sorter (taken from Java Tutorial page) which
> asks the model for the number of columns...
>
> What I did - it's working so far - is:
>
> model.setColumnCount(table.getColumnCount());
>
> Is this the recommended solution? (I believe not)
>
> Please, could somebody provide help?
>
> Thanks,
> Thomas

Here is an example:

http://www.exampledepot.com/egs/javax.swing.table/AppendCol.html

Claus Reibenstein

unread,
Jul 17, 2012, 3:22:19 PM7/17/12
to
Thomas Lehmann schrieb:

> You might wonder how this relates (title)...

Vor allem frage ich mich, warum Du hier englisch schreibst ...

> When using "addColumn" on a table instance the model will be not adjusted to it; this means that "model.getColumnCount()" is zero but table.getColumnCount() is > 0.

Diese ᅵberlangen Zeilen solltest Du Dir auch abgewᅵhnen.

Gruᅵ
Claus

Thomas Lehmann

unread,
Jul 20, 2012, 5:56:13 AM7/20/12
to
Erst mal tdschuldigung wegen dem Englisch ...
das kommt durch die Firma wo ich arbeite.

a) Ich rufe NICHT addColumn über das Model
sondern über die Table auf!
b) Dabei kann ich mit New TableColumn einen
frei definierbaren Index angeben; dafür
habe ich eine Enum Konstante.

Klartext: Bspw. 3 Spalten aber die Indize sind 1, 9, 41.

Deswegen muss man an ein paar Stellen die Konvertiermethoden
der Table nehmen (model <-> view).

Zurück zu meiner (englischen) Beschreibung:

Gehe ich diesen Weg dann liefert mein Model "getColumnCount()" -> 0.
Woher soll das Model es denn wissen?

Also setze ich die "3" in das Model (setColumnCount).
Aber auch nur deswegen weil der TableRowSorter auf "getColumnCount()"
zugreift.

Übrigens passieren die gleichen Probleme wenn man auf die Spalte klickt.
Ist der Wert der Konstante größer/gleich als die Anzahl der Spalten...

Entweder sind das Fehler im TableRowSorter Konzept oder ich habe irgendwas
wesentliches verpasst.

Könnte mir da jemand bitte weiterhelfen?
0 new messages