开发者

Updating a JTable after using RowFilter

开发者 https://www.devze.com 2023-01-23 17:17 出处:网络
I was able to attach a filter to the GraphTable (which is extended from the JTable). I was trying out a sample filter which filters all the rows starting with the letter \"A\".

I was able to attach a filter to the GraphTable (which is extended from the JTable). I was trying out a sample filter which filters all the rows starting with the letter "A".

final GraphTable<Composite, ?> leftTable =
        (GraphTable<Composite, ?>) newMapPanel.getLeft();
final RowSorter<TableModel> sorter =
        new TableRowSorter<TableModel>(((JTable)leftTable).getModel());

RowFilter<Object, Object> startsWithAFilter = new RowFilter<Object,Object>() {
   public boolean include(Entry<? extends Object, ? extends Object> entry) {

      for (int i = entry.getValueCount() - 1; i >= 0; i-开发者_如何学Python-) {
          if(entry.getValue(i) != null)
          {
              if (entry.getValue(i).toString().startsWith("A")) {
                // The value starts with "A", so do not include it, filter it.
                return false;
              }
          }
      }
      // None of the columns start with "a"; return true so that this
      // entry is shown
      return true;
   }
};

((DefaultRowSorter<TableModel, Integer>) sorter).setRowFilter(startsWithAFilter);
((JTable)leftTable).setRowSorter(sorter); 
((JTable)leftTable).updateUI();

The include method returns false for all the entries starting with "A" and returns true for others.

But this updation is not reflected in the Table. Neither ((JTable)leftTable).updateUI() nor the ((JTable)leftTable).revalidate() updated the Table. I believe this filter those rows from the view. What should I do to make the changes get reflected in the view immediately.

Kindly give me any directions or suggestions ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号