更新时间:2023-12-03 11:22:22
我确实找到了这个,但是不知道它是怎么回事...或者如何使用以下方法在jtable中设置ImageIcon和字符串:
I did find this but don't know what goes in ... or how to set the ImageIcon and string in the jtable with this:
您需要创建自定义对象(假设您将其称为MyCustomObject)来保存要显示的信息.因此,您的自定义对象将具有两个属性:图标和文本.
You need to create custom Object (lets say you call it MyCustomObject) to hold the information you want to display. So your custom Object will have two properties: Icon and Text.
然后创建对象,并像对表中的其他任何对象一样将其添加到TableModel中.
Then you create the Object and add to the TableModel like you do for any other Object in the table.
您需要重写getColumnClass()方法以为前两列返回MyCustomObject
.然后,您还需要为MyCustomObject
设置自定义渲染器.
You need to override the getColumnClass() method to return MyCustomObject
for the first two columns. Then you also need to set the custom renderer for the MyCustomObject
.
因此,在呈现代码中,您将执行以下操作:
So then in the rendering code you would do something like:
MyCustomObject data = (MyCustomObject)value;
setIcon(data.getIcon());
setText(data.getText());