Tag: filechooser

JFileChooser和使用JAVA从Excel文件读取

我有一个下面的代码 import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.text.html.HTMLDocument.Iterator; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Workbook; public class ExcelRead { public static String keep = ""; public static void main(String[] args) throws IOException { // File […]

如何为JFileChooser添加文件filter

我只想select.xls和.xlsx文件,但我无法select任何types的文件。 任何人都可以向我推荐任何代码,或者有人可以对我现有的代码进行更改吗? 提前致谢。 public class Convertor { public static void main(String[] args) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("choosertitle"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); } else { System.out.println("No Selection "); } } }

文件select器正在挑选出错的目录

我有一个相当简单的程序,一旦一些数据被input到一个JTable它可以被导出或“保存”到一个Excel电子表格。 所有这一切工作正常,它是完美的保存excel文件。 我碰到的问题是这样的: 当你尝试把excel文件放在桌面文件夹(桌面/文件夹)的子文件夹中时,它将它保存在桌面上。 但它只在Mac上做到这一点。 当我在Windows电脑上这样做的时候,它的工作时间是100%。 我想知道是否有人对这个问题有任何认识或解决办法? 这是我的JFileChooser代码,理论上会导致这个问题。 JFileChooser fc = new JFileChooser(); fc.setSelectedFile(new File(jTextField3.getText() + jTextField6.getText() + "-" + jTextField7.getText() + "-" + jTextField8.getText())); int option = fc.showSaveDialog(PScalcUI.this); if(option == JFileChooser.APPROVE_OPTION){ String filename = fc.getSelectedFile().getName(); String path = fc.getSelectedFile().getParentFile().getPath(); int len = filename.length(); String ext = ""; String file = ""; if(len > 4){ […]