图像不';单击Jtable时,java swing中不会显示
我想搜索图像并将其显示在图像不';单击Jtable时,java swing中不会显示,java,sql,image,swing,jtable,Java,Sql,Image,Swing,Jtable,我想搜索图像并将其显示在JLabel(标签名称为tampilFoto)中,然后将其作为长blob保存到数据库中,然后它就可以工作了。当我想在标签中显示图像时,用户单击JTable(表格名称为tblBalon),但图像不会显示,单击标签时不会显示任何错误 以下是上载图像的代码: private void tblFotoActionPerformed(java.awt.event.ActionEvent evt) {
JLabel
(标签名称为tampilFoto
)中,然后将其作为长blob保存到数据库中,然后它就可以工作了。当我想在标签中显示图像时,用户单击JTable
(表格名称为tblBalon
),但图像不会显示,单击标签时不会显示任何错误
以下是上载图像的代码:
private void tblFotoActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
String sumberFile = f.getAbsolutePath();
sumberFoto.setText(sumberFile);
ImageIcon icon = new ImageIcon(sumberFile);
Image image = icon.getImage().getScaledInstance(tampilFoto.getWidth(), tampilFoto.getHeight(), Image.SCALE_SMOOTH);
tampilFoto.setIcon(icon);
}
以下是单击表格时将图像显示到标签中的代码:
private void tblBalonMouseClicked(java.awt.event.MouseEvent evt) {
try {
int row = tblBalon.getSelectedRow();
nim.setText(tblBalon.getValueAt(row, 1).toString());
nama.setText(tblBalon.getValueAt(row, 2).toString());
fakultas.setSelectedItem(tblBalon.getValueAt(row, 3).toString());
prodi.setSelectedItem(tblBalon.getValueAt(row, 4).toString());
noUrut.setSelectedItem(tblBalon.getValueAt(row, 5).toString());
calon.setSelectedItem(tblBalon.getValueAt(row, 6).toString());
visi.setText(tblBalon.getValueAt(row, 7).toString());
misi.setText(tblBalon.getValueAt(row, 8).toString());
sumberFoto.setText(tblBalon.getValueAt(row, 9).toString());
String tampil = "SELECT * FROM databalon WHERE idBalon='"+row+"';";
ResultSet rst = stk.executeQuery(tampil);
byte[] image =null;
if(rst.next()){
Blob img = rst.getBlob("foto");
image = img.getBytes(1,(int)img.length());
BufferedImage imag = ImageIO.read(new ByteArrayInputStream(image));
ImageIcon ft = new ImageIcon(imag);
tampilFoto.setIcon(RImage(ft));
}
} catch (SQLException | IOException ex) {
Logger.getLogger(PanitiaDataBalon.class.getName()).log(Level.SEVERE, null, ex);
}
this.btnHapus.setEnabled(true);
this.btnUbah.setEnabled(true);
this.btnTambah.setEnabled(false);
this.btnBatal.setEnabled(true);
}
我的代码有什么不对吗?
你也应该考虑使用<代码> ReultStE.GETBIAQueStave代码> IMG.GETBACK(1,(int)img.Langthh());<代码>-不应该从0
开始,而不是1
开始。如果img.length
@MadProgrammer,我也会检查结果,所以我必须使代码变得像img.getBinaryStream(1,(int)img.length())代码>?您真的应该阅读