| View previous topic :: View next topic |
| Author |
Message |
Thomas Lehmann Guest
|
Posted: Mon Jul 16, 2012 10:24 am Post subject: JTable.addColumn and RowSorter.setSortKeys |
|
|
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 |
|
| Back to top |
|
 |
Claus Reibenstein Guest
|
Posted: Tue Jul 17, 2012 5:22 pm Post subject: Re: JTable.addColumn and RowSorter.setSortKeys |
|
|
Thomas Lehmann schrieb:
| Quote: | You might wonder how this relates (title)...
|
Vor allem frage ich mich, warum Du hier englisch schreibst ...
| Quote: | 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 |
|
| Back to top |
|
 |
S.van Heek Guest
|
Posted: Tue Jul 17, 2012 5:44 pm Post subject: Re: JTable.addColumn and RowSorter.setSortKeys |
|
|
Am Montag, 16. Juli 2012 12:24:20 UTC+2 schrieb Thomas Lehmann:
| Quote: | 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 |
|
| Back to top |
|
 |
Thomas Lehmann Guest
|
Posted: Fri Jul 20, 2012 9:56 am Post subject: Re: JTable.addColumn and RowSorter.setSortKeys |
|
|
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? |
|
| Back to top |
|
 |
|