Pessoal, estou com programa q adiciona a um jPanel vários jLabel com uma imagem em cada jLabel, agora estou precisando modificar o tamanho da imagem q eu inseri em casa jLabel. Eu consigo extrair o ícone do jLabel mas ñ estou conseguindo manipular e retornar para o ícone de novo… esta ai o código…
int cont=jPanel1.getComponentCount();
for(int e=0; e<cont; e++){
Icon icone = new ImageIcon(jPanel1.getComponent(e).getName());
//jPanel1.getComponent(e).getName() é a forma q eu estou passando
// o caminho da Imagem, ate aqui ta tranquilo, pois esta gerando
// o icone com a imagem q tinha no painel
BufferedImage fundo = null;
try {
fundo = ImageIO.read(new File(jPanel1.getComponent(e).getName()));
}
catch (IOException e1) {
fundo = new BufferedImage(1,1,BufferedImage.BITMASK );
}
// o erro é disparado na proxima linha de codigo
/*Exception in thread "AWT-EventQueue-0"
java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot
be cast to javax.swing.Icon*/
icone=(Icon) fundo.getScaledInstance(jPanel1.getComponent(e).getWidth(),
jPanel1.getComponent(e).getHeight(), 10000);
// icone.paintIcon((Component) icone, null, e, e);
JLabel jLabel = new JLabel();
jLabel.setIcon(icone);
jLabel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.WHITE));
jLabel.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabelMouseClicked(evt);
}
});
jPanel1.add(jLabel);
}
jPanel1.validate();