1.使用JFileChooser去获取文件路径
2.使用ImageIO读取路径下的图片
3.标签设置图片对象( jLabel1.setIcon(new ImageIcon(image))
4.代码演示
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author lenovo
*/
public class PersonIntroduce extends javax.swing.JFrame {
/**
* Creates new form PersonIntroduce
*/
public PersonIntroduce() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jtSex = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jtname = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jtNation = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jtAddress = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jtelephonenumber = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jbtPicture = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jbtSave = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 297, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 293, Short.MAX_VALUE)
);
jLabel2.setText("姓名");
jtSex.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel3.setText("性别");
jtname.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel4.setText("民族");
jtNation.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing<