如何在jlabel中显示来自jtable的图像?

时间:2017-07-07 16:09:47

标签: java user-interface binding jtable tablemodel

有没有办法在jtable上显示与jlabel上的mysql绑定的照片?我使用此代码在texfield中显示文字:

int selectedrow=jTable1.getSelectedRow();

TableModel model=(TableModel)jTable1.getModel();
jTextField7.setText(model.getValueAt(selectedrow, 0).toString());
jTextField6.setText(model.getValueAt(selectedrow, 1).toString());
jTextField5.setText(model.getValueAt(selectedrow, 2).toString());

jTextField1.setText(model.getValueAt(selectedrow, 3).toString());
jTextField2.setText(model.getValueAt(selectedrow, 4).toString());
jTextField4.setText(model.getValueAt(selectedrow, 5).toString());
jTextField3.setText(model.getValueAt(selectedrow, 6).toString());
jTextField8.setText(model.getValueAt(selectedrow, 7).toString());
jTextField9.setText(model.getValueAt(selectedrow, 8).toString());

我尝试添加此内容,但却提供了java.lang.ClassCastException: [B cannot be cast to javax.swing.ImageIcon

ImageIcon image=(ImageIcon) model.getValueAt(selectedrow,9);
Image image2=image.getImage().getScaledInstance(jLabel10.getWidth(),jLabel10.getHeight(),Image.SCALE_SMOOTH);
ImageIcon image3=new ImageIcon(image2);
jLabel10.setIcon(image3);

0 个答案:

没有答案