Question, do I just added a new method to do the add of of row to my
TableModel. And if so I guess that I would have to at the same time
issue a fireTableDataChanged() to complete the updated process. I will
be using seven table ala tabs that I need to keep the TableModels
separate which should be no problem.
It would be fine if I new what my data and columns was going to be and
have it defined, to the Model, before hand but I don't know what the
data will be. All I see in any examples are not really good examples of
a normal table use.
Sorry, I'm tied: a long day. I would have not problem using Mustang to
do what I need to do but then that would run me into distribution problems.
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
>
> I have always used the DefaultTableModel for JTables, no problem. It
> seems that I have to use TableModel and AbstractTableModel because I
> need to do some table sorting. I have it all setup having my TableModel
> loaded into the AbstractTableModel sorting model which is loaded into my
> jTable.. Naturally I have insert my data into my model. Problem is that
> TableModel is not defined to load data, other than at a row\column.
>
Have you looked at the TableSorter class which Sun provide as an example in the
Swing Tutorial?
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/TableSorter.java
This extends DefaultTableModel, and may do most of what you want. It might be
easier to start with this class and modify to suit your needs. When I needed a
sorted table that was what I did.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : n...@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Thanks Nigel.. Last night I had finally settled on using the TableSorter
because it implements the decorator pattern. I was also impressed by
what the TableSorter class does. The problem, for me, is that it
implements this pattern using the TableModel. Also the TableSorter
extends the AbstractTableModel not the DefaultTableModel.
Here lies my dilemma. If you used this Model how did you to say.. add
data, via calling program, to your data Model or say even columns? The
data model has to extend TableModel. Maybe I am wrong if you are using it?
AbstractTableModel has a bunch of fire methods, two of which are
fireTableStructureChanged and fireTableDataChanged. Is that what you're
missing?
--
Judy Szikora, Apprisant Technologies Inc.
http://www.apprisant.com
regards
Daniel
Thanks Dan.. that is what I am doing now as it turns out.
I always use the DefaultTableModel and never have any problems. So
really the Java Tutorial example for table sorting is not really a
workable example because most people do not hard code their columns and
data in their TableModel. OK.
I can not wait until 1.6 with it's new filtering and sorting mechanism.
Basically, I changed it so it extended DefaultTableModel rather than
AbstractTableModel.
Sorry, hit send by mistake...
It is necessary to override the addRow/insertRow/removeRow/setRowCount methods
of DefaultTableModel as there is some additional work to be done. One caveat of
adding/inserting/removing rows is that the sorting status needs to be reset.
There's also the added ambiguity with insert/remove as to which row number is
meant - the unsorted index or the sorted index. The same also applies to
getValueAt and setValueAt, the methods in TableSorter apply to the sorted index
which might not be what you want. I added the methods getUnsortedValueAt and
setUnsortedValueAt to work with the unsorted model data.
It's quite a lot of fun...
I based on your prior thread message I used the TableModel and just
added methods I needed: addRow(), addColumn() and methods to manage the
String[]columnNames and Object[][] data Objects.
I guess I really should not have done it this way because it does not
conform to the JComponent's MVC implementation.
I put it down a few days ago but I will revisit and convert it to use
the DefaultTableModel.