導航:首頁 > 版本升級 > 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選擇文件相關的資料

熱點內容
如何發word文件怎麼打開 瀏覽:176
惠普還原系統win10教程 瀏覽:167
iphone6ssunspider 瀏覽:796
java獲取攝像頭 瀏覽:959
怎麼用網線傳文件 瀏覽:24
電導增量法matlab程序 瀏覽:366
手機文件管理在那裡 瀏覽:205
如何取消卸載app的續費 瀏覽:316
數控編程哪個最容易 瀏覽:170
光速互動官方教程 瀏覽:411
谷歌登陸網站打不開怎麼辦 瀏覽:937
java什麼是非同步編程 瀏覽:898
怎麼刪除qq裡面的文件 瀏覽:503
qq鈴聲設置的鈴聲文件在哪裡找 瀏覽:421
有哪些有助於考公的app 瀏覽:237
四字qq網名 瀏覽:666
dcm格式文件能發給醫聖嗎 瀏覽:998
ps文件大卡頓是顯卡問題嗎 瀏覽:616
win7可以用win10易升嗎 瀏覽:56
企業qq營銷qq區別 瀏覽:322

友情鏈接