Link to home
Create AccountLog in
Avatar of desiboy1974
desiboy1974

asked on

list issue

hi,
  i have 3 buttons and a target jlist....each button runs its oen query to populate the list..so if i hit button 1 its populates the list with its items..

i'm using list.removeAll(); to clear the list and repopulate but it doesnt seem to work..so when i press button 1, it still jkeeps the items from button2 etc..
Avatar of Mick Barry
Mick Barry
Flag of Australia image

JList does not have aremoveAll() method, what are calling removeAll() on exactly.
Sounds like you are not firing the appropriate event after removing
if use DLM then use model.clear();
Avatar of desiboy1974
desiboy1974

ASKER

oh..i'm actually calling removeall() to clear and repopulate the items when the button is hit..so i need to use a datamodel?
yes you need to remove the items from the model
another option would be to create a new model using setModel() or setListData()
this is what i've done..but it still doesnt clear the data


 
 DefaultListModel modelList1 = new DefaultListModel();
 final JList list1 = new JList(modelList1);
 ----
 
 --  get data from database
 
 --


 ResultSet rs = pstmt.executeQuery();
       
        modelList1.clear();
       
        while (rs.next()) {
           
            modelList1.add(0,rs.getString(1));
        }
 }      
       
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
works fine thanks..