Java Swing: extend defaultcomboboxmodel and override methods

I use DefaultCombo@R_10_2419 @Model JCombo@R_10_2419 @List of customers in The list currently displays only its name I also hope DefaultCombo@R_10_2419 @Each customer is referenced in the model so that when you select a name, it also saves a reference to the real customer object

To achieve this, I suspect I must expand DefaultCombo@R_10_2419 @Model and may override the addelement () method? Or can I add a new method or store my reference to the customer? If so, do I have to check DefaultCombo@R_10_2419 @Model's source code to see how it stores elements? I'm sorry if this question is confusing, but I can't figure out how to do it in the right way Thank you for reading

Solution

If you override toString () in the customer object to return the JCombo@R_10_2419 @It will work properly If you use toString for other purposes, you need to override the model or renderer to use the correct fields in the customer object

– update Tom's suggestion – create a new object customerview, which wraps the real customer object, so you can provide a reference to it, but also override tostring() to return the customer's name

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>