欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入 GridBagConstraints gbc_browserButton1 = new GridBagConstraints(); gbc_browserButton1.insets = new Insets(0, 0, 5, 0); gbc_browserButton1.gridx = 4; gbc_browserButton1.gridy = 0; contentP
欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入
GridBagConstraints gbc_browserButton1 = new GridBagConstraints();
gbc_browserButton1.insets = new Insets(0, 0, 5, 0);
gbc_browserButton1.gridx = 4;
gbc_browserButton1.gridy = 0;
contentPane.add(browserButton1, gbc_browserButton1);
JLabel label_1 = new JLabel(
"\u9009\u62E9\u76EE\u6807\u6587\u4EF6\u5939\uFF1A");
GridBagConstraints gbc_label_1 = new GridBagConstraints();
gbc_label_1.anchor = GridBagConstraints.EAST;
gbc_label_1.insets = new Insets(0, 0, 5, 5);
gbc_label_1.gridx = 0;
gbc_label_1.gridy = 1;
contentPane.add(label_1, gbc_label_1);
targetFolderField = new JTextField();
GridBagConstraints gbc_targetFolderField = new GridBagConstraints();
gbc_targetFolderField.gridwidth = 3;
gbc_targetFolderField.insets = new Insets(0, 0, 5, 5);
gbc_targetFolderField.fill = GridBagConstraints.HORIZONTAL;
gbc_targetFolderField.gridx = 1;
gbc_targetFolderField.gridy = 1;
contentPane.add(targetFolderField, gbc_targetFolderField);
targetFolderField.setColumns(10);
JButton browserButton2 = new JButton("\u6D4F\u89C8");
browserButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
do_browserButton2_actionPerformed(e);
}
});
GridBagConstraints gbc_browserButton2 = new GridBagConstraints();
gbc_browserButton2.insets = new Insets(0, 0, 5, 0);
gbc_browserButton2.gridx = 4;
gbc_browserButton2.gridy = 1;
contentPane.add(browserButton2, gbc_browserButton2);
JLabel label_2 = new JLabel("\u64CD\u4F5C\u8BB0\u5F55\uFF1A");
GridBagConstraints gbc_label_2 = new GridBagConstraints();
gbc_label_2.anchor = GridBagConstraints.EAST;
gbc_label_2.insets = new Insets(0, 0, 5, 5);
gbc_label_2.gridx = 0;
gbc_label_2.gridy = 2;
contentPane.add(label_2, gbc_label_2);
JScrollPane scrollPane = new JScrollPane();
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.gridwidth = 4;
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 1;
gbc_scrollPane.gridy = 2;
contentPane.add(scrollPane, gbc_scrollPane);
infoArea = new JTextArea();
scrollPane.setViewportView(infoArea);
JButton moveButton = new JButton("\u79FB\u52A8");
moveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
do_moveButton_actionPerformed(e);
}
});
GridBagConstraints gbc_moveButton = new GridBagConstraints();
gbc_moveButton.insets = new Insets(0, 0, 0, 5);
gbc_moveButton.gridx = 1;
gbc_moveButton.gridy = 3;
contentPane.add(moveButton, gbc_moveButton);
JButton closeButton = new JButton("\u5173\u95ED");
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
do_closeButton_actionPerformed(e);
}
});
GridBagConstraints gbc_closeButton = new GridBagConstraints();
gbc_closeButton.insets = new Insets(0, 0, 0, 5);
gbc_closeButton.gridx = 2;
gbc_closeButton.gridy = 3;
contentPane.add(closeButton, gbc_closeButton);
}
/**
* 选择源文件的浏览按钮
*
* @param e
*/
protected void do_browserButton1_actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();// 创建文件选择器
chooser.setMultiSelectionEnabled(true);// 设置文件多选
int option = chooser.showOpenDialog(this);// 显示文件打开对话框
if (option == JFileChooser.APPROVE_OPTION) {
files = chooser.getSelectedFiles();// 获取选择的文件数组
sourceFolderField.setText("");// 清空文本框
StringBuilder filesStr = new StringBuilder();
for (File file : files) {// 遍历文件数组
filesStr.append("、" + file.getName());// 连接文件名称
}
String str = filesStr.substring(1);// 获取所有文件名称的字符串
sourceFolderField.setText(str);// 设置文件名称信息到文本框
} else {
files = new File[0];
sourceFolderField.setText("");// 清空文本框
}
}
/**
[1] [2] [3]