gpt4 book ai didi

java - 在 JTable 中显示图像

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:50:03 24 4
gpt4 key购买 nike

我正在尝试将图像显示到 JTable 的第 25 列中:- 为此,我编写了以下代码:-

    jTable1.getColumnModel().getColumn(25).setCellRenderer(jTable1.getDefaultRenderer(ImageIcon.class));
String query = "SELECT name,type,supplier, department, manufacturer, model, serial_no, description, location, broker, dop, installation_date, expiring_date, retiring_date,warranty_info, icost, rcost, aarea, voltage, wattage, amperage, eline, capacity, plink, notes, adding_date, modification_date from assets where company_code='" + ims.MainWindow.cc + "' and adding_date between '" + new java.sql.Date(df.parse(df.format(jXDatePicker1.getDate())).getTime()) + "' and '" + new java.sql.Date(df.parse(df.format(jXDatePicker2.getDate())).getTime()) + "'";
System.out.println(query);
ResultSet rs = st.executeQuery(query);
int xx = 1;
byte[] imagedata=null;
ImageIcon format=null;
java.awt.Image originalImage=null;
java.awt.Image scaledImage=null;

javax.swing.ImageIcon newIconImage=null;
while (rs.next()) {
if(rs.getBytes(24)!=null){
imagedata=rs.getBytes(24);
format = new ImageIcon(imagedata);
originalImage = format.getImage();
scaledImage = originalImage.getScaledInstance(268, 200, java.awt.Image.SCALE_SMOOTH);
newIconImage = new javax.swing.ImageIcon(scaledImage);
}
mod.addRow(new Object[]{xx, rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14), rs.getString(15), rs.getString(16), rs.getString(17), rs.getString(18), rs.getString(19), rs.getString(20), rs.getString(21), rs.getString(22), rs.getString(23), newIconImage, rs.getString(25), rs.getString(26), rs.getString(27)});
xx++;
}

当我运行包含以下代码的框架时,图像列中显示的不是图像列中的图标“javax.swing.ImageIcon@119537a”。请帮忙

最佳答案

您可以尝试更改设置图像图标渲染器的列号。即在

中尝试 24
jTable1.getColumnModel().getColumn(25).setCellRenderer(jTable1.getDefaultRenderer(ImageIcon.class));

我怀疑渲染器未针对您添加图像图标的列进行更改。

关于java - 在 JTable 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14829005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com