導航:首頁 > 版本升級 > swt使用filedialog選擇文件

swt使用filedialog選擇文件

發布時間:2024-04-13 10:10:55

1. 用java寫一個文件選擇窗口

其它辦法肯定是有的,用File就可以,只不過要自己繪制界面,這是個很淡疼的事。先獲得一個目錄下的所有文件,然後自己處理一下,排個序顯示出來,例子找不著了,以前寫過,思路就是那樣的。
Win8,聽起來很厲害的樣子,沒用過,不清楚。
通過FileDialog,當你打開一個目錄後,這個位置會被記錄下來,在你重新new這個FileDialog之前這個位置是不會變的。通常都是利用這一點來保存用戶上次選擇的位置。具體例子,沒有。(但是看你一說是win8下有,winxp下沒有,我覺得我說的好象沒什麼用處了。)

過濾文件格式是可以的,FileDialog是可以添加過濾器的。你怎麼什麼都要例子?
不過我在api里見到這樣 一句話,意思是windows的過濾器在sun的實現中,不起作用。
還有,我作為菜鳥都覺得分太低了,大神是不會來拯救你了。。。

2. java用swt 如何建立選擇文件夾路徑的對話框

FileDialog fileDialog = new FileDialog(shell);
fileDialog.getFileName();
fileDialog.getFilterPath();
fileDialog.open();

3. 瀹夎卝ava鏄劇ず鏁呴殰浠g爜涓1683浠涔堟剰鎬濓紵鎬庝箞瑙e喅錛

JAVA鑷甯︿簡鏂囦歡閫夋嫨瀵硅瘽妗嗐
鐢‵ileDialog銆
FileDialog dialog = new FileDialog (shell, SWT.OPEN);
dialog.setText("File Folder Selection");
dialog.setFilterExtensions(new String[] {"*.xml","*.wsdl","*.asmx","*.*"});
String filePath = dialog.open();
if(dialog!=null){
text_file.setText(filePath);
}

4. 奼俲ava婧愪唬鐮併備嬌鐢╯wing鎴朅WT銆傚疄鐜板姛鑳:鐐瑰嚮鎸夐挳錛岄夋嫨涓涓猼xt鏂囨湰鏂囦歡錛屽苟灝唗xt涓

鎼炲畾浜

packagecom.monubia;
importjava.awt.event.MouseAdapter;
importjava.awt.event.MouseEvent;
importjava.io.BufferedReader;
importjava.io.FileNotFoundException;
importjava.io.FileReader;
importjava.io.IOException;

importjavax.swing.JButton;

importjavax.swing.JDialog;
importjavax.swing.JFileChooser;
importjavax.swing.JTextArea;
importjavax.swing.WindowConstants;
importjavax.swing.SwingUtilities;
importjavax.swing.filechooser.FileNameExtensionFilter;


/**
*'sJigloo
*SWT/SwingGUIBuilder,whichisfreefornon-commercial
*use.(ie,byacorporation,
*)thenyou
*.
*Pleasevisitwww.cloudgarden.comfordetails.
*.
*
*THISMACHINE,
*.
*/
publicclassTxtextendsjavax.swing.JFrame{
privateJButtonjButton_open;
privateJTextAreajTextArea1;

/**
*Auto-
*/
publicstaticvoidmain(String[]args){
SwingUtilities.invokeLater(newRunnable(){
publicvoidrun(){
Txtinst=newTxt();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}

publicTxt(){
super();
initGUI();
}

privatevoidinitGUI(){
try{
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jButton_open=newJButton();
getContentPane().add(jButton_open);
jButton_open.setText("Open");
jButton_open.setBounds(155,114,92,49);
jButton_open.addMouseListener(newMouseAdapter(){
publicvoidmouseClicked(MouseEventevt){
jButton_openMouseClicked(evt);
}
});
}
{
jTextArea1=newJTextArea();
getContentPane().add(jTextArea1);
jTextArea1.setBounds(0,0,384,262);
}
pack();
setSize(400,300);
}catch(Exceptione){
//addyourerrorhandlingcodehere
e.printStackTrace();
}
}

privatevoidjButton_openMouseClicked(MouseEventevt){
//鐐瑰嚮浜嗘墦寮
JFileChooseropen=newJFileChooser();
FileNameExtensionFiltertxt=newFileNameExtensionFilter("TxtFile","txt");
open.setFileFilter(txt);
intret=open.showOpenDialog(this);
if(ret==JFileChooser.APPROVE_OPTION)
{
jButton_open.setOpaque(false);
jButton_open.setVisible(false);
System.out.println(open.getSelectedFile().getAbsolutePath());
try{
BufferedReaderbr=newBufferedReader(newFileReader(open.getSelectedFile().getAbsolutePath()));
Stringline=null;
while((line=br.readLine())!=null)
{
jTextArea1.append(line+" ");
}
}catch(FileNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}

}
閱讀全文

與swt使用filedialog選擇文件相關的資料

熱點內容
凍結qq號能防申訴嗎 瀏覽:861
數據今年與過去幾年年比較叫什麼 瀏覽:564
矩陣理論需要什麼數據 瀏覽:252
如何批量導入音頻文件名及時長 瀏覽:881
撓癢癢視頻在哪個app有得看 瀏覽:773
陳三和陳墨涵在哪個app里直播 瀏覽:747
es文件管理器手機管理電腦文件 瀏覽:659
cad文件一直崩 瀏覽:501
微信怎麼製作文件夾視頻 瀏覽:752
飛行器攝像頭升級替換 瀏覽:184
qq昵稱帶英文 瀏覽:374
中信銀行usbkey密碼幾位 瀏覽:174
helloword單詞比賽 瀏覽:57
java測試環境搭建 瀏覽:195
手機解密壓縮文件 瀏覽:991
微信文件夾里的圖片如何刪除 瀏覽:383
表格匯入數據怎麼填寫代碼 瀏覽:103
歌奈和品勝數據線哪個好用 瀏覽:714
為什麼銷售易下載app 瀏覽:630
網上編程哪個好 瀏覽:814

友情鏈接