[英]How to set a default file name to Swing JFileChooser?
我想在此JFileChooser
文本框中將默認文件名設置為Untitled.txt
。 我可以設置嗎?
使用以下代碼:
JFileChooser fileChooser = new JFileChooser();
File file = new File("C:/untitled.txt");
fileChooser.setCurrentDirectory(file);
您必須指定untitled.txt
的完整路徑
您必須使用setSelectedFile方法並將文件作為參數傳遞。 該文件不必存在。
如果指定了文件的路徑,則文件選擇器將嘗試指向文件目錄(如果存在)
JFileChooser fileChooser = new JFileChooser(); fileChooser.setSelectedFile(new File("C:\\\\file.txt")); fileChooser.showSaveDialog(null);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.