• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in displaying 2 different icons in jtree

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
may be some one will help, developing an instant messanger application using smack, used jtree for displaying all users, i want to show green icon for users who are online and grey icons to show users offline. below is the code i used but the problem is:



here is the full code below. it should work but dont know what i am lacking and why its not working. pleassse help or update me thaks
I hope some one would help.

calling -- jTree1.setCellRenderer(new IconNodeRenderer()); in the main programs constructor

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!
Can you please UseCodeTags next time? I've added them for you this time.

If you've found a match you don't quit - you check the next child. And that's no longer a match so you call setIcon(signOut). A quick fix is to call break; after setIcon(signIn). This will prevent other nodes to be checked.

Another, possibly better solution is to change your entire data model. Instead of storing indexes, use a Set to store the actual online users. Then to check if a user is online, simply get the user from the node (getUserObject()) and checking if the Set of online users contains the user. That does require you to override equals and hashCode in your user class.

I also have problems with that if statement. root.getChildAt(i) == root.getChildAt((Integer)indexPositionofOnlineUsers.elementAt(i)) can only be true if i == (Integer)indexPositionofOnlineUsers.elementAt(i), unless you actually added a node to the root more than once. Which I doubt.
 
zishan khan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Rob,
thank you for the quick reply.

i put the break after setIcon(signIn) but still no luck they all green, dont know why, i can see if it is showing green icons its showing green to all buddy list and if it is showing grey icons it iss showing all grey icons , why its not setting the icons even after the condition is met. is there any other way of setting icons in jtree or what i am doing wrong dont know may be there is some basic mistake which i am doing.

yes you are right it should be through string matching which is names but i can see a basic problem with that idea is
//r.getName is displaying name like - Merry Rose
and
// is giving the string like - merry.rose@gmail.com/Talk.v104F96A51EC

also some times r.getname is giving null where there are no names set.
comparing string names will be a difficult task in such situation but i will try to do it with strings and not with indexes, right now i am just figuring out the status of online users once the code will work then i know how i can mould a working code, its a sort of hit and try situation i am stuk with the logic once i got the basics working then I will smooth my code.

thanks again for help.
awaiting.

zishan

reply
    Bookmark Topic Watch Topic
  • New Topic