Solved

Problem in updating the JList

Posted on 2006-06-17
8
335 Views
Last Modified: 2008-01-16
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
Comment
Question by:deeppra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 26

Accepted Solution

by:
ksivananth earned 25 total points
ID: 16928831
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16928987
You may have threading issues. What does setListData do?
0
 
LVL 1

Assisted Solution

by:FunnyMan
FunnyMan earned 25 total points
ID: 16929823
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
Technology Partners: 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!

 
LVL 5

Author Comment

by:deeppra
ID: 16930401
>>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16930697
>>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
 
LVL 1

Expert Comment

by:FunnyMan
ID: 16930844
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 74
arguments to jar 5 40
IBM TS2900 (3572) Tape Autoloader Java? 12 61
Find out all repos that a user is most active on Github 1 34
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question