linux查看文件內(nèi)容過濾 jFileChooser使用方法?
jFileChooser使用方法?JFileChooserjFileChooser=newJFileChooser()inti=jFileChooser.showOpenDialog(null)如果(
jFileChooser使用方法?
JFileChooserjFileChooser=newJFileChooser()inti=jFileChooser.showOpenDialog(null)如果(i==jFileChooser.APPROVE選項(xiàng)){//打開文件stringpath=jFileChooser.getSelectedFile文件().getAbsolutePath()字符串名稱=jFileChooser.getSelectedFile文件().getName()系統(tǒng)輸出打?。ā爱?dāng)前文件路徑:”路徑“n當(dāng)前文件名:”名稱)}否則{系統(tǒng)輸出打?。ā皀o file selected”}
將以下代碼添加到密鑰事件監(jiān)視方法://初始化文件選擇框Jfilechooser fdialog=new Jfilechooser()//設(shè)置文件選擇框的標(biāo)題fDialog.setDialogTitle設(shè)置對話框標(biāo)題(“please select audio file”//彈出選擇框int returnval=fDialog.showOpenDialog文件(null)//如果選擇了文件,如果(JFileChooser.APPROVEOption==returnval){//打印文件的路徑。您可以修改位以將路徑值寫入textfield 系統(tǒng)輸出打印( fDialog.getSelectedFile文件())}
如何給jfilechooser中的打開和取消按鈕設(shè)置不同的監(jiān)?
Jfilechooser filechooser=new Jfilechooser()//創(chuàng)建文件選擇器文件選擇器.setCurrentDirectory(新文件()?!啊?/設(shè)置當(dāng)前目錄filechooser.setAcceptAllFileFilterUsed已使用(false)//顯示所有文件filechooser.addChoosableFileFilter(新建)javax.swing.filechooser文件選擇器. filefilter(){public Boolean accept(file f){return true}public string getdescription(){return“所有文件(*)。*) "})