tags:

views:

163

answers:

2

I am trying to figure out how to get the program to create a text string based on which item in a jlist is selected. At first I tried

ListModel custTypetxt = custType.getModel();
System.out.println(custTypetxt);

but that just gave me..

customerInfoUI$3@1820dda
+1  A: 

You need to get the selection from the list first. Call
custType.getSelectedValue()
(or getSelectedValues() for multiple selections). That will return the selected object. The you can get the string from the object any way you want (like toString() if it has been properly implemented by the class).

Carlos
A: 

It looks like you are getting the right object so you need to create a toString() method in the customerInfoUI class.

 public String toString(){
    return "String that describes my object";
 }

Then your code will print whatever you return from the toString method. The default implementation of toString in the Object class returns <classname> @ hascode which is what you are seeing when you run the code.

Vincent Ramdhanie