Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList & Observer

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic