java Swing 选择框

来源:互联网 发布:查看淘宝店铺数据 编辑:程序博客网 时间:2024/05/21 04:43
public class FileChoice {private static JFileChooser fileChooser = null;private static JFileChooser fileDown = null;private static String filePath = "";private static String outPath = "";// 选择框private static JFileChooser getFileChooser() {if (fileChooser == null) {fileChooser = new JFileChooser();fileChooser.setFileFilter(null);fileChooser.setFileFilter(new FileNameExtensionFilter("XLS and XLSX Files", "xls", "xlsx"));fileChooser.setFont(new Font("Dialog", Font.PLAIN, 12));fileChooser.setMultiSelectionEnabled(false);}return fileChooser;}public  String getUploadFile() {int res = getFileChooser().showOpenDialog(null);if (res == JFileChooser.APPROVE_OPTION) {File file = getFileChooser().getSelectedFile();filePath = file.getAbsolutePath();System.out.println("ccccccccccccccccc:" + file.getAbsolutePath());}return filePath;}// 保存框public static String getFileDown() {if (fileDown == null) {fileDown = new JFileChooser();fileDown.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);}int returnVal = fileDown.showOpenDialog(null);if (returnVal == JFileChooser.APPROVE_OPTION) {System.out.println("You chose diriction: "+ fileDown.getSelectedFile().getPath());outPath = fileDown.getSelectedFile().getPath() + "\\";System.out.println(outPath + "ddddddddd");}return outPath;}}

1 0