更改ImageImplement图像

时间:2013-05-24 08:45:08

标签: java swing jpanel imageicon

每次我将上传的图像更改为图像数组时,它会在上一张图像旁边绘制图像。如何让下一张选定的图片出现在第一张图片上?

ImageImplement panel = new ImageImplement(new ImageIcon(images[0]).getImage());
add(panel);
getContentPane().setLocation(200, 0);

setVisible(true);
setSize(800,700);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setBackground(Color.black);

2 个答案:

答案 0 :(得分:0)

您可以使用JLayeredPane,因为这允许您在另一个上创建图层:

[实施例] JLayeredPane and painting

这可能有助于上面的链接显示如何重叠面板你也可以为图片做。

答案 1 :(得分:0)

  

它在上一张图像旁边绘制图像。如何让下一张选定的图片出现在第一张图片上?

不要继续创建新组件。我猜你有类似的代码:

JLabel image = new JLabel( new ImageIcon(...) );
panel.add( image );

相反,只需更改当前标签的图标:

image.setIcon( new ImageIcon(...) );