L
Lizard
OK.
I have a tabbed form.
Each tab has a (different) table on it.
Each table is based on a .CSV file.
For each table, I want to use a custom cell editor for integers, and
another for floating points, and the generic cell editor for
everything else. I've written and tested the two custom cell editors.
The tableModel for all the tables is an ArrayList of ArrayLists of
Objects.
For each specific table, I have two Vectors, one containing a list of
Integer columns, one containing a list of Floating Point columns.
As I read the CSV, I use a string tokenizer to break the row up, then
add each element to an ArrayList<Object>, then add the
ArrayList<Object> to an ArrayList<ArrayList<Object>>, then pass that
to the TableModel. This all works fine.
As each item is added, I check the position in the token list against
the Vectors which contain the Float or Integer colummns. IOW, if we're
at item 3, and IntegerVector.contains(3), I cast the data to Integer
before adding it. If the column isn't in either IntegerVector or
DoubleVector, it is cast to a String.
Thus, every column is cast to either Integer, Double, or String.
Then I have:
theTable.setDefaultEditor(Double.class, new
FloatingPointCellEditor());
theTable.setDefaultEditor(Integer.class, new IntegerCellEditor());
And no errors are thrown.
However, it doesn't work. The default editor is used for all cells.
The code
theTable.getColumnModel().getColumn(x).setCellEditor(newIntegerCellEditor());
does work, but it's easier for me to create a vector of columns than
to hard-code in the column editors one column at a time.
I guess my main question is, if I define my tableModel as
ArrayList<ArrayList<Object>>, and make sure all the Objects in, say,
colum 3 are Doubles, does this mean that the JTable automagically
knows that data is of type Double?
I have a tabbed form.
Each tab has a (different) table on it.
Each table is based on a .CSV file.
For each table, I want to use a custom cell editor for integers, and
another for floating points, and the generic cell editor for
everything else. I've written and tested the two custom cell editors.
The tableModel for all the tables is an ArrayList of ArrayLists of
Objects.
For each specific table, I have two Vectors, one containing a list of
Integer columns, one containing a list of Floating Point columns.
As I read the CSV, I use a string tokenizer to break the row up, then
add each element to an ArrayList<Object>, then add the
ArrayList<Object> to an ArrayList<ArrayList<Object>>, then pass that
to the TableModel. This all works fine.
As each item is added, I check the position in the token list against
the Vectors which contain the Float or Integer colummns. IOW, if we're
at item 3, and IntegerVector.contains(3), I cast the data to Integer
before adding it. If the column isn't in either IntegerVector or
DoubleVector, it is cast to a String.
Thus, every column is cast to either Integer, Double, or String.
Then I have:
theTable.setDefaultEditor(Double.class, new
FloatingPointCellEditor());
theTable.setDefaultEditor(Integer.class, new IntegerCellEditor());
And no errors are thrown.
However, it doesn't work. The default editor is used for all cells.
The code
theTable.getColumnModel().getColumn(x).setCellEditor(newIntegerCellEditor());
does work, but it's easier for me to create a vector of columns than
to hard-code in the column editors one column at a time.
I guess my main question is, if I define my tableModel as
ArrayList<ArrayList<Object>>, and make sure all the Objects in, say,
colum 3 are Doubles, does this mean that the JTable automagically
knows that data is of type Double?