Not able to filter rows of jtable with textfield in netbeans

Not able to filter rows of jtable with textfield in netbeans

DBOperations objDB;
ArrayList alstStock;
public TableRowSorter sorter;
public void viewDailyStock() {
initComponents();
setSize(Toolkit.getDefaultToolkit().getScreenSize());
objDB = new DBOperations();
alstStock = objDB.getStockList();
generateTable();
txtSearch.getDocument().addDocumentListener(
        new DocumentListener() {
    @Override
            public void changedUpdate(DocumentEvent e) {
                newFilter();
            }
    @Override
            public void insertUpdate(DocumentEvent e) {
                newFilter();
            }
    @Override
            public void removeUpdate(DocumentEvent e) {
                newFilter();
            }
        });
setVisible(true);
}
void generateTable() {
Object data[][] = new Object[alstStock.size()][10];
String date = null;
for (int i = 0; i < alstStock.size(); i++) {
    StockBean objBean = (StockBean) alstStock.get(i);
    data[i][0] = i + 1;
    data[i][1] = objBean.getBrand();
    data[i][2] = objBean.getProductCode();
    data[i][3] = objBean.getProductName();
    data[i][8] = objBean.getItemInBox();
    SimpleDateFormat df = new SimpleDateFormat("EEEE, MMM d,yyyy");
    date = df.format(objBean.getDate());
    data[i][4] = date;
    data[i][5] = objBean.getUser();
    data[i][6] = objBean.getLotNumber();
    data[i][7] = objBean.getQtyInItem();
    data[i][9] = objBean.getQtyInBox();
}
String header[] = {"S.No.", "Brand", "Code", "Name", "Date", "Added By", "Lot No.", "Qty In Item", "Item", "Qty In Boxes"};

tblStock = new JTable(data,header);
sorter=new TableRowSorter(tblStock.getModel());
tblStock.setRowSorter(sorter);
jScrollPane1.setViewportView(tblStock);
setWidth();
tblStock.setAutoCreateRowSorter(true);

}
public void newFilter() {
RowFilter rf = null;
try {
    rf = RowFilter.regexFilter(txtSearch.getText(), 3);
} catch (java.util.regex.PatternSyntaxException e) {
    System.out.println("Exception "+e);
}
sorter.setRowFilter(rf);
}

DBOperations is a class for fetching data from database table. StockBean is a class of object with the getter and setter method.

This is my code of implementing row filter to the 4th column of jtable with a textfield but its not working means it is not filtering data and even i am not getting any exception. Please help me...

View Answers

Ads









Related Tutorials/Questions & Answers:
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ... of implementing row filter to the 4th column of jtable with a textfield but its...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ... of implementing row filter to the 4th column of jtable with a textfield but its...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new
Advertisements
How to insert rows in jTable?
How to insert rows in jTable?  Hi, I need to take input from user using JTable. I want an empty row to appear after clicking a insert button... not figure out how to. I used DefaultTableModel but wasnt able to insert a row
Not able to display jtable at runtime
Not able to display jtable at runtime  Hello, can anyone please help...[][] taskcells; JTable ttable; public void BuildTable() { Statement st; ResultSet rs...=new JTable(tasktable); TableColumnModel columnModel
search filter and JTable
search filter and JTable  I first im not speak englis very well, so my question is: how can i make search data in JTable of java? i wan to search records in table or textfield but the data display in JTable. Note: i dont
Shading Rows in JTable
Shading Rows in JTable     ... the shading rows in JTable. But, the question arises what is shading?.  Shading Rows: In JTable component the shading rows are the simplest way of shading
Getting the Number of Rows and Columns in JTable
will learn how to get the number of rows and columns in JTable.  This program simply helps us for getting the number of rows and columns from the JTable by using... Getting the Number of Rows and Columns in JTable 
Inserting Rows in a JTable
Inserting Rows in a JTable     ... in a table. This tutorial helps you in how to insert rows in a JTable to specified locations or places according to its field. For inserting a row in JTable component
how to enable textfield in j2me netbeans when a choice element is selected?
how to enable textfield in j2me netbeans when a choice element is selected?  How to enable a textfield in j2me using netbeans when a choice element is selected and how to keep it disabled when any choice element corresponding
how to enable textfield in j2me netbeans when a choice element is selected?
how to enable textfield in j2me netbeans when a choice element is selected?  How to enable a textfield in j2me using netbeans when a choice element is selected and how to keep it disabled when any choice element corresponding
Show multiple identical rows into JTable from database
Show multiple identical rows into JTable from database In this tutorial, you will learn how to display the multiple rows from database to JTable. Here... rows from database on clicking search button to jtable. The given code accepts
Setting the Height and Width of Rows and columns in JTable
Setting the Height and Width of Rows and columns in JTable... in JTable. Earlier, you have read about the JTable that contains the data in rows... to set the height and width of rows and columns in JTable. This table has
how to print fasta file into jtable using netbeans IDE
how to print fasta file into jtable using netbeans IDE   mt file... in netbeans IDE. when i click the any row in jtable,particular sequence should... "and"contig00002 length=554 numreads=4" in jtable having three columns
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database table so i want to display both or any number of identicle rows in the jtable .I am...How to show multiple identicle rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database table so i want to display both or any number of identicle rows in the jtable .I am...How to show multiple identicle rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database table so i want to display both or any number of identicle rows in the jtable .I am...How to show multiple identicle rows from database on clicking search button
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract.... And i'm not able to set value to a particular column. How can i do it? Please
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
Create a Custom Cell Renderer in a JTable
in given output of table. The even rows of a JTable contains cyan color and odd rows... Create a Custom Cell Renderer in a JTable       After getting the knowledge about the JTable
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
netbeans
netbeans  guysss m nt able to opemn ma netbeans ide.. no error msg s coming... wn i installed yesterday one msg came stating about some run time error... sm one plzzzzzz hlp me
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
NetBeans
NetBeans  Hi, I am Kundan I have made a project on NetBeans. And now I want to know that how can i run my project without NetBeans IDE,on other PC. Please help me it's important
NetBeans
NetBeans  Hi, I am Kundan I have made a project on NetBeans. And now I want to know that how can i run my project without NetBeans IDE,on other PC. Please help me it's important
jtable
jtable  i have build an application and i retrieve data from the database and store it in jtable.now i have to make a checkbox column in each row and also a select all option in header but i am not able to do so.i am getting

Ads