this code below works for filtering JTable until I use english alphabet. It is also not case-sensitive. My goal is to filter white spaces and foreign characters. I need to replace characters in needle and in haystack somehow, for example ?,?,?,?,y,á replace with c,l,t,z,y,a.
Does anybody have experience or working code for my request? Thanks in advance.
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
public class Home extends javax.swing.JFrame {
DefaultTableModel model;
TableRowSorter sorter;
public Home() {
initComponents();
model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
String data[] = {"?ing","?amg","búng","wámg","fáng","raňk","moňk","pú?k","?ank","dung","puck","rig","an da da","ku nd ada","c ic inada"};
for(int i=0;i<data.length;i++) {
model.addRow(new Object[] {
data[i]
});
}
sorter = new TableRowSorter<TableModel>(model);
jTable1.setRowSorter(sorter);
}
private void initComponents() {///}
private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {
String text = jTextField1.getText();
if(text.length() == 0) {
sorter.setRowFilter(null);
} else {
sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
}
}
public static void main(String args[]) {///}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…