java - JList selected item to String - Weird result: Donnees.Marques@3d5bac58 -


i try , result not value of item value donnees.marques@3d5bac58

listcategories.addmouselistener(new mouseadapter() {             @override             public void mouseclicked(mouseevent arg0) {                 string selectedcategories = listcategories.getselectedvalue().tostring();                 system.out.println(selectedcategories);             }         }); 

per default when use .tostring() method on own objects printing memory address string. same reason compare 2 objects .equals() , not ==, default thing you're tampering object memory address.

to fix need override super object's tostring metod, this:

public class listmodel {  // ...      @override     public string tostring()     {         string text = "i want print when call listmodel.tostring()";          return text;     } } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -