Eventhandling with TableSorter and TableFilterer

Discussion in 'Java' started by cm, Aug 5, 2004.

  1. cm

    cm Guest

    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!
    cm, Aug 5, 2004
    #1
    1. Advertising

  2. cm

    Rogan Dawes Guest

    cm wrote:
    > 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

    --
    Rogan Dawes

    *ALL* messages to will be dropped, and added
    to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
    Rogan Dawes, Aug 5, 2004
    #2
    1. Advertising

  3. cm

    cm Guest

    Rogan Dawes <> wrote in message news:<ceth52$4g0$>...
    > cm wrote:
    > > 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


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

    Christian
    cm, Aug 9, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert
    Replies:
    3
    Views:
    553
    Tris Orendorff
    Oct 6, 2003
  2. Tim
    Replies:
    1
    Views:
    431
    Tim Ward
    May 19, 2004
  3. VisionSet

    Sun's swing TableSorter

    VisionSet, Jun 2, 2004, in forum: Java
    Replies:
    8
    Views:
    806
    Shane Petroff
    Jun 7, 2004
  4. farseer

    TableSorter NPE exception

    farseer, Jun 23, 2005, in forum: Java
    Replies:
    7
    Views:
    745
    suvacodecobra
    Nov 16, 2006
  5. Michi
    Replies:
    2
    Views:
    96
    TheBagbournes
    Jun 13, 2006
Loading...

Share This Page