小编use*_*951的帖子

浏览图像文件并使用Java Swing显示它

我的问题是,点击Browse按钮后会显示要选择的目录中的所有文件,然后所选图像会正确显示在GUI中.但是当我第二次单击"浏览"按钮时,它仅显示旧图像而不是显示新图像.请帮帮我.

作为参考,我上传了UI.

package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics2D;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;


@SuppressWarnings("serial")
public class MainAppFrame extends JFrame {

    private JPanel contentPane;
    File targetFile;
    BufferedImage targetImg;
    public JPanel panel,panel_1;
    private static final int baseSize = 128;
    private static final String basePath =![enter image description …
Run Code Online (Sandbox Code Playgroud)

java eclipse swing jfilechooser image

9
推荐指数
2
解决办法
4万
查看次数

标签 统计

eclipse ×1

image ×1

java ×1

jfilechooser ×1

swing ×1