File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList & Observer

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic