JTable, JComboBox using custom Objects

陌路散爱 提交于 2019-12-05 07:19:33
camickr

The problem is that your TableModel is storing a String object and the ComboBox contains a Test object. These objects are not equal so there is no item to select and it looks the first is automatically highlighted.

Change your code to the following and you will see the same problem with an unknown string:

{"Joe", "Brown", "Pool?????", new Integer(10), new Boolean(false)}

To fix the problem, I would guess you need to do the following:

{"Joe", "Brown", new Test("Pool"), new Integer(10), new Boolean(false)}

You would then need to implement the equals() method in your Test class to compare the name property of both components. As well, you would need to implement the hashcode() method.

In the future, as Andrew suggested, include your SSCCE with your question as we don't have time to copy/paste/edit and test code because we never know if we do it exactly the same way you do.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!