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);
|
}
|
}
|
}
|