File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JList & Observer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList & Observer" Watch "JList & Observer" New topic
Author

JList & Observer

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Guys,
I am developing simple chat application and I have a problem with JList:
ChatWindow extends JFrame implements Observer {
// ---
private JList onlineUsersList = new JList();
public ChatWindow() {
Container contentPane = getContentPane();
contentPane.add(new JScrollPane(onlineUsersList),
BorderLayout.EAST);
DefaultListModel model = new DefaultListModel();
onlineUsersList.setModel(model);
// ----
}

public void update(Observable obs, Object obj) {
final DefaultListModel model =
(DefaultListModel) onlineUsersList.getModel();
model.addElement("From update");
onlineUsersList.setModel(model);
}
}
What's wrong here ?
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList & Observer
 
Similar Threads
Swing and pattern observer
JList not refreshing ?issue?
JList : how to add one simple element to a existing list??
I need help creating a custom ListModel
How to update JList