在applet的窗口中显示图片,使用JLabel,而非Label.JPanel应该也可以.
调用JLable的setIcon方法.Icon应为一个ImageIcon.
因为你是从数据库中读出图片数据,如果是blob,取得的数据应为byte[].
方法如下:
byte[] imageBytes = //get from db
ImageIcon ii = new ImageIcon(imageBytes);
jLabel1.setIcon(ii);
如果你在数据库中的只是图片url,则应由此url读数据到一个ByteArrayOutputStream
(或者ByteArrayInputStream),再转化为byte[],产生imageicon,方法如上.
如下:
try {
ByteArrayOutputStream byteArrays = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(byteArrays);
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(
new File("D:\\tmp\\SMP09.JPG")));
int iRead = bis.read();
while(iRead != -1) {
bos.write(iRead);
iRead = bis.read();
}
ImageIcon ii = new ImageIcon(byteArrays.toByteArray());