从 Object[][] 转换为 ImageIcon
Converting from Object[][] to ImageIcon
我正在尝试将我的 object[][]
转换为 ImageIcon
。我目前有一个 public Object[][] images;
存储图像的地方。如何将其转换为 ImageIcon 以便我可以使用它来将其放入我的 JTable 中?我试过这个:
for(int i = 0; i < 100; i++)
{
...
ImageIcon icon = new ImageIcon(images[i].toString());
// add to table
}
我的 table 中没有显示任何内容,如果我从单元格中打印出值,则会显示:[Ljava.lang.String;@72787a6f
感谢您的回答。
您有一个二维数组,因此您需要使用另一个索引来引用行 i
列 j
中的元素
for (int i = 0; i < images.length; i++) {
for (int j = 0; j < images[i].length; j++) {
ImageIcon icon = new ImageIcon(images[i][j].toString());
...
}
}
使用 String[][]
数组
更有意义
我正在尝试将我的 object[][]
转换为 ImageIcon
。我目前有一个 public Object[][] images;
存储图像的地方。如何将其转换为 ImageIcon 以便我可以使用它来将其放入我的 JTable 中?我试过这个:
for(int i = 0; i < 100; i++)
{
...
ImageIcon icon = new ImageIcon(images[i].toString());
// add to table
}
我的 table 中没有显示任何内容,如果我从单元格中打印出值,则会显示:[Ljava.lang.String;@72787a6f
感谢您的回答。
您有一个二维数组,因此您需要使用另一个索引来引用行 i
列 j
for (int i = 0; i < images.length; i++) {
for (int j = 0; j < images[i].length; j++) {
ImageIcon icon = new ImageIcon(images[i][j].toString());
...
}
}
使用 String[][]
数组