Click to See Complete Forum and Search --> : JList wont update
keko2005
05-11-2005, 07:07 AM
hey guys, im trying to make a JList which shows the contents of asn array. the problrm that im having is, at first the array is blank when the jlist is used, then aupon clicks of buttons to add stuff to the array, the JList should update with new elements that are in the array. i tried using jl.setListData(array);, but it doesnt update, stays blank. any reason for this? maybe someone has came across the same problem with the JLists? thanks
buntine
05-11-2005, 08:45 AM
Where are you calling setListData from?
keko2005
05-11-2005, 02:24 PM
after and action accurs(click of a button), the setListData is done int the ActionPerformed() method.
Khalid Ali
05-11-2005, 04:42 PM
did u try to debug and see that if in effect when a button is clicked it really saves data in JList?
If not then you know where is the problem, but if it does save it then it could be that its not refreshing it etc..but first verify the first option I mentioned.
buntine
05-11-2005, 08:07 PM
You did call it actionPerformed() and not ActionPerformed(), right? The first character needs to be in lowercase. Java is case-sensitive.
Regards.
keko2005
05-11-2005, 08:18 PM
yes i did, every other action works, except that. any other suggestions?
buntine
05-11-2005, 08:34 PM
I need code.
Khalid Ali
05-11-2005, 08:40 PM
did u try to debug and see that if in effect when a button is clicked it really saves data in JList?
If not then you know where is the problem, but if it does save it then it could be that its not refreshing it etc..but first verify the first option I mentioned.
just wondering if you bothered reading or implementing the above
keko2005
05-11-2005, 09:46 PM
the array updates, i know this, cause everytime i added the customer, i printed that element in the array, and it printed every customer i added, so im pretty sure it updates. how do i check to see if the list infact the list gets updated?
keko2005
05-13-2005, 09:09 PM
hey guys, i found my jlist problem, i tried to print the array, and all i got were null values, i used this code to fill the array, can someone tell my why it doesnt work when i print the array, but when i do System.out.println(c[index]);
it prints the name of the customer?
heres the actions performed method im using:
public void actionPerformed(ActionEvent e){
if(e.getSource() == jbtAC){
if(!jtfFirst.getText().equals("") && !jtfLast.getText().equals("")){
c[index] = new Customer(jtfFirst.getText(),jtfLast.getText());
jlbMessage.setText(jtfFirst.getText() + " , " + jtfLast.getText() + " has been succesfully added");
System.out.println(c[index]);
index++;
}
else{
jlbMessage.setText("Sorry, there was an error, fields must not be blank");
}
}
}