swingx
  1. swingx
  2. SWINGX-1349

Patch for setRowFilter() method in JXTable

    Details

    • Issuezilla Id:
      1,349

      Description

      At the moment it is only possible to use "TableModel" as generic parameter in
      "setFilter(RowFilter<? super TableModel, ? super Integer> filter)".

      e.g.

      DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
      JXTable table = new JXTable(model);
      table.setAutoCreateRowSorter(true);
      RowFilter<DefaultTableModel, Integer> filter = RowFilter.regexFilter("240", 1);
      table.setRowFilter(filter); // error

      wont work, because of this error:
      The method setRowFilter(RowFilter<? super TableModel,? super Integer>) in the
      type JXTable is not applicable for the arguments
      (RowFilter<DefaultTableModel,Integer>)

      In JTable to set a RowFilter, you use an instance of TableRowSorter<M extends
      TableModel> where "setRowFilter(RowFilter<? super M, I super Integer> filter)"
      is given. That means the first generic parameter has to be a "? super M extends
      TableModel" type. To do this directly in JXTable, you can use this way:

      public <R extends TableModel> void setFilter(RowFilter<? super R, ? super
      Integer> filter) {
      if (hasSortController())

      { // all fine, because R is a TableModel (R extends TableModel) SortController<R> sorter = (SortController<R>) getSortController(); sorter.setRowFilter(filter); }

      else {
      // no sort controller
      if (getRowSorter() instanceof DefaultRowSorter<?, ?>)

      { // all fine, because R is a TableModel (R extends TableModel) DefaultRowSorter<R, Integer> sorter = (DefaultRowSorter<R, Integer>) getRowSorter(); sorter.setRowFilter(filter); }

      }
      }

      For an example see
      http://forums.java.net/jive/thread.jspa?threadID=153486&tstart=0 (for JTable and
      JXTable)

      That issue may address all other swingx components with "setRowFilter()" as well.

        Activity

        Hide
        kleopatra added a comment -

        applied the patch (slightly changed) to JXTable/JXList

        the slight change is to do nothing if the hasSortController is false: JXTable guarantees
        to not touch the RowSorter if it can't do it completely

        Show
        kleopatra added a comment - applied the patch (slightly changed) to JXTable/JXList the slight change is to do nothing if the hasSortController is false: JXTable guarantees to not touch the RowSorter if it can't do it completely
        Hide
        kleopatra added a comment -

        .

        Show
        kleopatra added a comment - .

          People

          • Assignee:
            kleopatra
            Reporter:
            cronid
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: