Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图像不';单击Jtable时,java swing中不会显示_Java_Sql_Image_Swing_Jtable - Fatal编程技术网

图像不';单击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())?您真的应该阅读