0

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

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.