gui 中重画的问题
第一次选择图像时,效果很好。但当我尝试更改它时,它不起作用,第一个图像保留在屏幕上。
label = new JLabel("");
panel_1.add(label);
btnAddImage = new JButton("Select Image");
btnAddImage.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
File f = null ;
fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int value = fileChooser.showOpenDialog(fileChooser);
if (value == JFileChooser.APPROVE_OPTION)
{
f = fileChooser.getSelectedFile();
if (f.exists())
{
inputImage_textField.setText(f.getName());
BufferedImage bi = getMyBuffImage();
label = new JLabel(new ImageIcon(bi));
label.setBounds(0, 68, 98, 92);
panel_1.add(label);
panel_1.repaint();
}
}
}
});
是我重画时做错了什么还是其他问题?
谢谢
The first time a choose a image, it works just fine. But it does not work when I try to change it, the first image remains on the screen.
label = new JLabel("");
panel_1.add(label);
btnAddImage = new JButton("Select Image");
btnAddImage.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
File f = null ;
fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int value = fileChooser.showOpenDialog(fileChooser);
if (value == JFileChooser.APPROVE_OPTION)
{
f = fileChooser.getSelectedFile();
if (f.exists())
{
inputImage_textField.setText(f.getName());
BufferedImage bi = getMyBuffImage();
label = new JLabel(new ImageIcon(bi));
label.setBounds(0, 68, 98, 92);
panel_1.add(label);
panel_1.repaint();
}
}
}
});
Am I doing something wrong when I repaint or something else is the problem?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想替换现有的标签,替换
为
或者如果你想添加第二个标签,只需替换
为
If you want to replace the existing label, replace
with
Or if you want to add a second label, just replace
with