java - JTable uptade or refresh -


i have class creates table :

import javax.swing.*; import javax.swing.table.*;  import java.awt.*; import java.util.*;  public class itemstable extends jpanel {    arraylist < item > items = new arraylist < item > ();    itemstable(arraylist < item > items, integer choice, string search) {     super(new gridlayout(1, 0));     this.items = items;      string[] columnnames = {       "no.",       "title",       "description",       "keyword",       "user id",       "start time",       "close time",       "reserve price",       "id code"     };      defaulttablemodel model = new defaulttablemodel(0, 0);     jtable table = new jtable();     model.setcolumnidentifiers(columnnames);     table.setmodel(model);      int k = 0;      (item i: items) {       if ((choice == 0 && i.getuserid().equals(search)) || (choice == 1 && i.getkeyword().equals(search)) || (choice == 2 && i.getidcode().equals(search))) {         k++;         object[] newrow = {           k, i.gettitle(), i.getdescription(), i.getkeyword(), i.getuserid(), i.getstarttime(), i.getclosetime(), i.getreserveprice(), i.getidcode()         };         model.addrow(newrow);       }     }      table.setpreferredscrollableviewportsize(new dimension(500, 70));     table.setfillsviewportheight(true);      jscrollpane scrollpane = new jscrollpane(table);      add(scrollpane);   }  } 

i want search values in table, choose column i'm looking , search string in column.

in class have search button :

searchbutton.addactionlistener(new actionlistener() {   public void actionperformed(actionevent arg0) {     integer choice = searchbox.getselectedindex();     system.out.println(choice);     itemstable table = new itemstable(items, choice, searchfield.gettext());     //searchpanel.add(table, borderlayout.south);   } }); 

but after search once, next time want search table doesn't change. how can update or refresh ?


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -