简体   繁体   中英

update jtable model after filtering

I want to apply the filter to the JTable.

            String text = textField.getText();
            rowSorter = new TableRowSorter<>(tableModel);
            this.getjTable1().setRowSorter(rowSorter);
            this.getjTable1().removeAll();
            if (text.trim().length() == 0) {
                rowSorter.setRowFilter(null);
            } else {
                //String regex = String.format("^%s$", text);
                if(jCheckBoxExtract.isSelected()){
                    text="^"+text+"$";
                }
                else{
                    if(!text.contains(".")||text.contains("$"))text="^"+text;
                }
                RowFilter rowFilter = RowFilter.regexFilter(text, 1);
                rowSorter.setRowFilter(rowFilter);
            }
            this.getjTable1().repaint();   

this code work but now, if I want to get a value in jtable, the model doesn't update. The model use in jtable is always the old model but not the new model after filter.

要获得适当的值,请在需要表中的行时执行以下操作:

model.getSelectedEntry(table.convertRowIndexToModel(table.getSelectedRow()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM