Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with .contains and the defaultListModel  RSS feed

 
Nathan Topper
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, I'm working on a small multicast chat program for school. Since there's no centralized server to store a user list on, I'm trying to get the program to parse and incoming message and extract the user name, then check the list model using .contains to see whether to add it or not. The problem comes when I try to verify. I was having some luck using a (string.equals(listModel.elementAt(i))) in a loop, but I was having issues the client's name being duplicated. I switched to listModel.contains(String) and now the client's name doesn't duplicate, but the program also doesn't add any more names. Any help would be appreciated.

edit: My appologies. It was late when I posted and it seemed like a good idea.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are not interested in degugging your real program. 90% of the code posted is not related to your problem. Your question is about the contains() method.

So create a SSCCE that demonstrates the problem. The SSCCE would contain a text field and a JList. When you hit enter on the text field you would add the typed text to the JList. This way the program will be about 15 lines of code and we will easily be able to see what you are doing.

Once we solve the problem with the simplied code you should be able to apply the solution to your real program.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!