how can i update my table with Jtextfield filtering?
Hi all
I have a big problem :( and i accept any help .
I have a Jtable that show the all customers list that there are in database.
On this table there is textfield for filtering. When a user type a character in the textfield , table must be update and show all customers that their names started by that character same time. For example when i type 's' in textfield ,table would synchronize show all customer list that start with s like 'sara' without pressing any key . I write this code , but it don't work and hass DBexeption.I want use of typedkey event .Please help
// below code is in myFrame.java
private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {
String st=evt.getKeyText(2);
newCall(st);
}
// Variables declaration - do not modify
private javax.swing.JTable customerTable;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
private void newCall(String st){
newFill();
try {
List<Customer> customerList = CustomerDAO.getInstance().listCustomersWithName(st );
Vector customerData = new Vector();
for (Customer c : customerList) {
Vector v = c.getCustomerData();
customerData.add(v);
}
Vector column = new Vector();
column.add("pass");
column.add("phone");
column.add("assress");
column.add("name");
column.add("id");
DefaultTableModel model = new DefaultTableModel(customerData, column);
customerTable.setModel(model);
} catch (DBException ex) {
JOptionPane.showMessageDialog(null, "database exception .");
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private void newFill(){
Vector customerData = new Vector();
customerData=null;
Vector column = new Vector();
column=null;
DefaultTableModel model = new DefaultTableModel(customerData, column);
customerTable.setModel(model);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
private void fillCustomerList() {
try {
List<Customer> customerList = CustomerDAO.getInstance().listCustomers();
Vector customerData = new Vector();
for (Customer c : customerList) {
Vector v = c.getCustomerData();
customerData.add(v);
}
Vector column = new Vector();
column.add("pass");
column.add("phone");
column.add("assress");
column.add("name");
column.add("id");
DefaultTableModel model = new DefaultTableModel(customerData, column);
customerTable.setModel(model);
} catch (DBException ex) {
JOptionPane.showMessageDialog(null, "database exception .");
}
}
Regars,