我正在使用下一个代码在label中显示图像,在picture列为空时不设置标签:

  ResultSet rset2 = stmnt.executeQuery("select Picture from Pictures where Client_ID_pass =1" );
                    while(rset2.next()){
                        byte[] Passimg = rset2.getBytes("Picture");
                        //Resize The ImageIcon
                    ImageIcon Passimage = new ImageIcon(Passimg);
                    Image Passim = Passimage.getImage();
                    Image PassmyImg = Passim.getScaledInstance(PassLBL.getWidth(), PassLBL.getHeight(),Image.SCALE_SMOOTH);
                    ImageIcon newPassImage = new ImageIcon(PassmyImg);
                    PassLBL.setIcon(newPassImage);

                if(Passimg.length < 0){
PassLBL.settext("No Picture");
PassLBL.setIcon(null);
                }
                    }

我试过下一个:
if(Passimg.equals(空)
{PassLBL.settext(“没有图片”);}
试过了
如果(Passimg==null)
{PassLBL.settext(“没有图片”);}
但没用!

最佳答案

从结果集中检索数据时

 byte[] Passimg = rset2.getBytes("Picture");

把if语句放在那里
if(passimg == null) {
   label.setText("nothing")
   lable.setIcon(null);//to remove the old picture
}else {
//show the image like you did before
 lable.setText("");
 icon=create your icon here
 lable.setIcon(icon);
}

我不明白你到底需要什么希望这能帮到你

10-06 05:46