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
Post a Comment