Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

Problem in updating the JList

Hai,
 i am doing a chat application in java applet. I used JList to display all the user present in the chat room, when a new user is loged in then using
user_list.setListData(user_list_vector);

 i added the user and call this method
user_list.updateUI(); to update the list with new values.

 But sometimes its get updated, in sometimes its not getting updated. To check whether the ListModel gets updated i used the following code System.out.println(user_list.getModel().getSize()); which shows new size of the user list, but its not getting updated. Tell me whats the problem

Thanks
0
deeppra
Asked:
deeppra
2 Solutions
 
ksivananthCommented:
0
 
CEHJCommented:
You may have threading issues. What does setListData do?
0
 
FunnyManCommented:
updateUI() isn't the method you want.  That one's checking to see if there's a new Look And Feel set as the default.  The command you're looking for is validate().
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
deeppraAuthor Commented:
>>>You may have threading issues

no i dont have any threads
>>>What does setListData do
This is a method in JList to set the ListModel with new data

i dont know we have to use validate();
The list model gets updated but the items in the list is not appearing

0
 
CEHJCommented:
>>This is a method in JList to set the ListModel with new data

Ah i haven't come across that one. *Try* calling validate on the Container holding the JList
0
 
FunnyManCommented:
Take a look at the Java API (http://java.sun.com/j2se/1.5.0/docs/api/).  The bottom left pane is the list of classes, clicking up one will bring up a class description in the right pane, which gives you an overview of the class, descriptions for all of its methods and fields, and links back to methods and fields it's inherited.  In this case, it's inherited the method validate, which takes no arguments, you call it like this: myList.validate();  According to the API:

"public void validate()

Validates this container and all of its subcomponents.

The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed"

In other words, when you want to make sure that the component (in this case the JList) displays all the new information you just gave it, call validate().   Contrast that to updateUI:

"public void updateUI()

Resets the UI property with the value from the current look and feel."

That's not at all what you wanted.  Just use validate instead, that's the method you thought you were calling.

-FM
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now