ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.vci.client.portal.Formdesign.widget;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.EventListener;
 
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
 
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJFileChooser;
 
public class FileChooserJPanel extends JPanel implements ActionListener, EventListener{
 
    /**
     * 
     */
    private static final long serialVersionUID = 3826672608143240090L;
 
    private JTextField text = new JTextField();
    private VCIJButton button = VCISwingUtil.createVCIJButton("fileChooser", "", "", "search.gif", this);
    private VCIJFileChooser vciJFileChooser =null;
    private String filePath = "";
    
    public String getText() {
        return text.getText().toString().trim();
    }
 
    public void setText(String string) {
        text.setText(string);
    }
 
    public String getFilePath() {
        return filePath;
    }
 
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
 
    public FileChooserJPanel(){
        super();
        init();
    }
    
    private void init(){
//        setLayout(new GridBagLayout());
//        GridBagConstraints c = new GridBagConstraints();
//        c.gridx = 0;
//        c.gridy = 0;
//        c.gridheight = 1;
//        c.gridwidth = 1;
//        c.weightx = 1;
//        c.weighty = 1;
//        c.anchor = GridBagConstraints.NORTHWEST;
//        c.fill = GridBagConstraints.BOTH;
//        text.setSize(130, 25);
        text.setPreferredSize(new Dimension(130, 25));
//        add(text, c);
//
//        c.gridx = 1;
//        c.gridheight = 1;
//        c.gridwidth = 1;
//        c.weightx = 0;
//        c.weighty = 0;
//        c.anchor = GridBagConstraints.EAST;
//        c.fill = GridBagConstraints.NONE;
//        add(button, c);
//        
//        c.gridx = 2;
//        c.gridheight = 1;
//        c.gridwidth = 1;
//        c.weightx = 0;
//        c.weighty = 0;
//        c.anchor = GridBagConstraints.EAST;
//        c.fill = GridBagConstraints.NONE;
//        VCIJLabel lbl = new VCIJLabel("  ");// 为显示
//        add(lbl, c);
        setLayout(new BorderLayout());
        add(text,BorderLayout.CENTER);
        add(button,BorderLayout.EAST);
        text.setEditable(false);
    }
 
    public void actionPerformed(ActionEvent e) {
        vciJFileChooser = new VCIJFileChooser();
        vciJFileChooser.setDialogTitle("打开");
        int result = vciJFileChooser.showOpenDialog(this);  // 打开"打开文件"对话框
        if (result == JFileChooser.APPROVE_OPTION) {
        File file = vciJFileChooser.getSelectedFile();
         filePath = file.getAbsolutePath();
         text.setText(filePath);
        }
    }
}