Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

JTable search

$
0
0
Im using AbstractTableModel and i want to type in a textfield for example "mairy" and to show me only objects from arraylist with name "mairy"..Can someone show me the correct way to do it? :whistling:/>


 public class Model extends AbstractTableModel{       
        private String[] header = {"        Contact List"};
        private ContactList contactList; //ArrayList 
        
        public Model() {
            contactList = new ContactList();
        }
        
        @Override
        public int getRowCount() {
            if(contactList.getContacts().size() < 10){      
                return 35;                            
            }
                return contactList.getContacts().size();
        }
        
        @Override
        public int getColumnCount() {
                return header.length;
        }
        
        @Override
         public String getColumnName(int column) {
                return header[column];           
        }
        
        @Override
        public Object getValueAt(int row, int column){
                
        if(row < 0 || row >= contactList.getContacts().size()) {
                return null;                                   
        }   
        
        Contact c  = contactList.getContacts().get(row); 
        switch(column)
        {     
            case 0: if( c != null ) {
                return  c.getName();
            }   
                default: return null;
        }        
        }
   
        public void addToList(Contact c) {
               contactList.addContact(c);
        }
        
        public void removeFromList(Contact c) {
               contactList.removeContact(c);  
        }
        
        public ContactList getContactList() {
               return contactList;          
        }    
    }
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>