Eventhandling with TableSorter and TableFilterer

C

cm

I want to use the TableSorter from Suns Tutorial and an additional
TableFilter, who works as an Decorator for a JTable as well.(Both are
tableModels, that overrite functions of the underlying TableModel, to
filter and sort the view of the Model)

simple Example code looks like this:
----------------------------
// making Model
TableModel tm = new TableModel(MyDataVector);
// give it to Filter
TableFilter tf = new TableFilterer(tm);
TableRowFilter filter = new TableRowFilter(3,"x",1);
tf.addRowFilter(filter);
// give Filter to Sorter
TableSorter ts = new TableSorter(tf);
// give Sorter to Table
JTable myTable = new JTable(ts);
ts.setTableHeader(myTable.getTableHeader());
myTable.getTableHeader().setToolTipText("Click to sort!");

// if event occures:
tf.removeAllRowFilters();
TableRowFilter filter2 = new TableRowFilter(3,"y",1);
tf.addRowFilter(filter2);
// then do not know how to fire the Event, thats the Problem!
tf.fireTableDataChanged();
ts.fireTableDataChanged();
myTableModel.fireTableDataChanged();
----------------------------

How do I coordinate the fireTableDataChanged() Events, with this tree
nested TableModels?
The Problem is simply, that when I switch the Filter, the Table do not
show Data, which defnitly is still in the Modell, and which in fact
has to go through the Filter.

Please Help!
 
R

Rogan Dawes

cm said:
I want to use the TableSorter from Suns Tutorial and an additional
TableFilter, who works as an Decorator for a JTable as well.(Both are
tableModels, that overrite functions of the underlying TableModel, to
filter and sort the view of the Model)

simple Example code looks like this:
----------------------------
// making Model
TableModel tm = new TableModel(MyDataVector);
// give it to Filter
TableFilter tf = new TableFilterer(tm);
TableRowFilter filter = new TableRowFilter(3,"x",1);
tf.addRowFilter(filter);
// give Filter to Sorter
TableSorter ts = new TableSorter(tf);
// give Sorter to Table
JTable myTable = new JTable(ts);
ts.setTableHeader(myTable.getTableHeader());
myTable.getTableHeader().setToolTipText("Click to sort!");

// if event occures:
tf.removeAllRowFilters();
TableRowFilter filter2 = new TableRowFilter(3,"y",1);
tf.addRowFilter(filter2);
// then do not know how to fire the Event, thats the Problem!
tf.fireTableDataChanged();
ts.fireTableDataChanged();
myTableModel.fireTableDataChanged();
----------------------------

How do I coordinate the fireTableDataChanged() Events, with this tree
nested TableModels?
The Problem is simply, that when I switch the Filter, the Table do not
show Data, which defnitly is still in the Modell, and which in fact
has to go through the Filter.

Please Help!

Looks like you should be firing the tableDatachanged() event from inside
the addRowFilter() method.

Rogan
 
C

cm

Rogan Dawes said:
Looks like you should be firing the tableDatachanged() event from inside
the addRowFilter() method.

Rogan

Hi Rogan,
sorry, it was an error in my implementation, the sorter and the filter
are working fine.

Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top