swt使用filedialog选择文件|java用swt 如何建立选择文件夹路径的对话框

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){//addyourerrorhandlingcodeheree.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-generatedcatchblocke.printStackTrace();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}}


赞 (0)