Aí, brother ViniGodoy!!!!!!!!!!!!!
Consegui!!! Ufaaaaa!!!
Estou muito agradecido pelas dicas... Foram muito úteis!
Então segue a maneira como consegui para quem passar pelo mesmo problema...
Adicionei a classe JImagePanel com a implementação dos demais métodos...
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.TexturePaint;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class JImagePanel extends JPanel {
private BufferedImage image = null;
private FillType fillType = FillType.RESIZE;
public JImagePanel(BufferedImage img) {
setImage(img);
}
public JImagePanel(File imgSrc) throws IOException {
this(ImageIO.read(imgSrc));
}
public JImagePanel(String fileName) throws IOException {
this(new File(fileName));
}
public final void setImage(BufferedImage img) {
if (img == null)
throw new NullPointerException("Sem imagem para processar!");
this.image = img;
invalidate();
}
public void setImage(File img) throws IOException {
setImage(ImageIO.read(img));
}
public void setImage(String fileName) throws IOException {
setImage(new File(fileName));
}
public BufferedImage getImage() {
return image;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
fillType.drawImage(this, g2d, image);
g2d.dispose();
}
public FillType getFillType() {
return fillType;
}
public void setFillType(FillType fillType) {
if (fillType == null)
throw new IllegalArgumentException("Invalid fill type!");
this.fillType = fillType;
invalidate();
}
public static enum FillType {
RESIZE {
public void drawImage(JPanel panel, Graphics2D g2d, BufferedImage image) {
g2d.drawImage(image, 0, 0, panel.getWidth(), panel.getHeight(),
null);
}
},
CENTER {
public void drawImage(JPanel panel, Graphics2D g2d, BufferedImage image) {
int left = (panel.getHeight() - image.getHeight()) / 2;
int top = (panel.getWidth() - image.getWidth()) / 2;
g2d.drawImage(image, top, left, null);
}
},
SIDE_BY_SIDE {
public void drawImage(JPanel panel, Graphics2D g2d, BufferedImage image) {
Paint p = new TexturePaint(image, new Rectangle2D.Float(0, 0, image.getWidth(), image.getHeight()));
g2d.setPaint(p);
g2d.fillRect(0, 0, panel.getWidth(), panel.getHeight());
}
};
public abstract void drawImage(JPanel panel, Graphics2D g2d, BufferedImage image);
}
}
Depois, instanciei um "quadroImagem" logo no início da classe onde quero visualizar as imagens resgatadas do banco...
private JImagePanel quadroImagem = null;
E então resgato a imagem adicionando-a ao quadroImagem e o quadroImagem ao JPanel, toda vez que precisar mudar a imagem. Note que não foi necessário retirar o quadroImagem para adicionar outra imagem devido ao bem pensado método "setImage()"... Outro ponto positivo que encherguei foi o resgate dos bytes para uma BufferedImage sem a utilização de codecs, como alguns fazem, pois assim eu consegui visualizar com esse mesmo código imagens do tipo jpg, png e gif (que foram as que testei)...
ResultSet rs = stmt.executeQuery("Select Imagem_Log from Logomarcas where Identificacao_Log = '"+identLogo+"'");
if (rs.next()) {
BufferedImage img = ImageIO.read(new ByteArrayInputStream(rs.getBytes("Imagem_Log")));
if (quadroImagem == null) quadroImagem = new JImagePanel(img);
quadroImagem.setImage(img);
painelImagem.add(quadroImagem);
painelImagem.repaint();
}
rs.close();
Agora preciso apenas redimensionar a imagem ao tamanho do JPanel mantendo o aspect ratio da imagem, porque o redimensionar dessa classe altera tanto a altura quanto a largura para as dimensões exatas do JPanel...
Se souber como vou fazer isso, agradeceria...
Um abraço!