導航:首頁 > 編程語言 > java文件選擇器

java文件選擇器

發布時間:2022-08-03 18:48:16

1. java調用的文件選擇器如何獲取它選擇的地址

//選擇的文件,如果是jfilechooser設置了setMultiSelectionEnabled(true);就是File[]file
Filefile=null;
//文件選擇器類型是打開文件,如果是保存文件,用showSaveDialog(null)。
//點擊「打開」或「保存」返回APPROVE_OPTION
if(chooser_multi.showOpenDialog(null)==JFileChooser.APPROVE_OPTION){
//如果是多選的,用getSelectedFiles()
file=chooser_multi.getSelectedFile();
}

2. java調用windows自帶的文件(夾)選擇器

但java不能直接call dll呀。一定要寫一個jni去調用windows的文件選擇器,再用java去調用jni。。很麻煩,所以建議不要啦,需要java的是難看了點。

3. Java如何製作文件選擇器

jsp嗎?<input type="file"/> 不就行了。要是swing,就是樓下說的

4. Java如何做出好看的本地文件選擇器

更改一下外觀為windows的:
if(UIManager.getLookAndFeel().isSupportedLookAndFeel()){
final String platform = UIManager.getSystemLookAndFeelClassName();
// If the current Look & Feel does not match the platform Look & Feel,
// change it so it does.
if (!UIManager.getLookAndFeel().getName().equals(platform)) {
try {
UIManager.setLookAndFeel(platform);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}

如果不需要文件過濾可以選擇 FileDialog來打開文件,這個是調用操作系統的文件筐打開文件的,但是在window下實現不了文件過濾,其他系統下可以。如果用JFileChoose可以很容易實現,文件過濾,但是界面默認是java外觀。如果要好看,可以設置一下顯示外觀。

5. JAVA 文件選擇器 左上角的小圖標 要怎麼改成自己的圖片,默認是JAVA的圖標。我用了改JFrame的圖標的句

Get the instance of JFrame, set image icon for the JFrame, then just by passing this JFrame to filechooser component the Icon would get reflected for JFileChooser also.
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(frm);

中文意思,是把調用的主窗口的圖標,先修改,再給JFileChooser。。。。。。。。。

6. java 中怎麼通過文件選擇器選擇要保存文件的的目錄,然後返回絕對路徑

JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.showOpenDialog(null);
String path = chooser.getSelectedFile().getPath();
System.out.println(path);

7. 急求一個簡單的java 界面程序 實現一個選擇本地電腦文件的功能

importjava.io.*;
importjava.awt.*;
importjavax.swing.*;
importjava.awt.event.*;
{
JFrameframe=newJFrame("文件選擇器實例");
JTabbedPanetabPane=newJTabbedPane();//選項卡布局
Containercon=newContainer();//布局1
Containercon1=newContainer();//布局2
JLabellabel1=newJLabel("選擇目錄");
JLabellabel2=newJLabel("選擇文件");
JTextFieldtext1=newJTextField();
JTextFieldtext2=newJTextField();
JButtonbutton1=newJButton("...");
JButtonbutton2=newJButton("...");
JFileChooserjfc=newJFileChooser();//文件選擇器
YFileChooser(){
jfc.setCurrentDirectory(newFile("d:\"));//文件選擇器的初始目錄定為d盤
//下面兩行是取得屏幕的高度和寬度
doublelx=Toolkit.getDefaultToolkit().getScreenSize().getWidth();
doublely=Toolkit.getDefaultToolkit().getScreenSize().getHeight();
frame.setLocation(newPoint((int)(lx/2)-150,(int)(ly/2)-150));//設定窗口出現位置
frame.setSize(300,150);//設定窗口大小
frame.setContentPane(tabPane);//設置布局
//下面設定標簽等的出現位置和高寬
label1.setBounds(10,10,70,20);
label2.setBounds(10,30,100,20);
text1.setBounds(80,10,120,20);
text2.setBounds(80,30,120,20);
button1.setBounds(210,10,50,20);
button2.setBounds(210,30,50,20);
button1.addActionListener(this);//添加事件處理
button2.addActionListener(this);//添加事件處理
con.add(label1);
con.add(label2);
con.add(text1);
con.add(text2);
con.add(button1);
con.add(button2);
con.add(jfc);
tabPane.add("目錄/文件選擇",con);//添加布局1
tabPane.add("暫無內容",con1);//添加布局2
frame.setVisible(true);//窗口可見
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//使能關閉窗口,結束程序
}
publicvoidactionPerformed(ActionEvente){//事件處理
if(e.getSource().equals(button1)){//判斷觸發方法的按鈕是哪個
jfc.setFileSelectionMode(1);//設定只能選擇到文件夾
intstate=jfc.showOpenDialog(null);//此句是打開文件選擇器界面的觸發語句
if(state==1){
return;//撤銷則返回
}
else{
Filef=jfc.getSelectedFile();//f為選擇到的目錄
text1.setText(f.getAbsolutePath());
}
}
if(e.getSource().equals(button2)){
jfc.setFileSelectionMode(0);//設定只能選擇到文件
intstate=jfc.showOpenDialog(null);//此句是打開文件選擇器界面的觸發語句
if(state==1){
return;//撤銷則返回
}
else{
Filef=jfc.getSelectedFile();//f為選擇到的文件
text2.setText(f.getAbsolutePath());
}
}
}
publicstaticvoidmain(String[]args){
newYFileChooser();
}
}

不用謝~請叫我雷鋒

8. Java (文件選擇器) 保存文件

兄弟,從圖片上看看我做的一個小例子,你就會明白的!

9. Java中編寫出一個文件選擇器。能選擇文件夾的。

JFileChooser 就行, 參考以下幫助文檔JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}

10. Java里的文件選擇器是干什麼用得

Java里的文件選擇器是方便用戶在硬碟上選擇文件的,這里有個程序你可以看一下,就知道文件選擇器怎麼用了。
import java.awt.*;

import javax.swing.*;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import java.io.*;
import java.awt.event.*;
public class Test11 extends JFrame{
//添加一個顏色對話框窗口
JFrame color=new JFrame();
JDialog color_diglog=new JDialog(color,"顏色",true);
Container contentpane=this.getContentPane();
JTextArea text=new JTextArea();//文本域
JFileChooser filechooser=new JFileChooser();//文件選擇器
JColorChooser colorchooser=new JColorChooser();//顏色選擇器
ColorSelectionModel model=colorchooser.getSelectionModel();//用以獲取顏色模型
//創建菜單欄
JMenuBar menubar=new JMenuBar();
JMenu F_menu=new JMenu("文件(F)"),
C_menu=new JMenu("顏色(C)");
JMenuItem FC=new JMenuItem("打開(文件選擇器)"),
CC=new JMenuItem("顏色(顏色選擇器)");
public Test11(){
super("簡單文本編輯器");//調用父類(JFrame)的構造方法
contentpane.setLayout(new BorderLayout());
text.setLineWrap(true);
F_menu.add(FC);
C_menu.add(CC);
menubar.add(F_menu);
menubar.add(C_menu);
contentpane.add(menubar,"North");
contentpane.add(text);

color_diglog.add(colorchooser);
color_diglog.setSize(300, 400);
fileshow();//事件監聽器類
}
public void fileshow(){
//文件查看器
FC.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int result=filechooser.showOpenDialog(null);
File file=filechooser.getSelectedFile();
if(file!=null&&result==JFileChooser.APPROVE_OPTION){
try {//將讀出的文件賦給text,text用read方法讀出
FileReader fr=new FileReader(file.getPath());
text.read(fr,null);
fr.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}

}
});
//顏色查看器
CC.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
color_diglog.setLocationRelativeTo(Test11.this);//在color_dialog中顯示顏色選擇器
model.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e){
text.setBackground(colorchooser.getColor());//將文本域的背景色改變為獲取的顏色
}
});
color_diglog.setVisible(true);
}
});
}
public static void main(String[] args) {
JFrame f=new Test11();
f.setBounds(300,300,300,300);
f.setVisible(true);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e){
System.exit(0);
}
});
}

}

閱讀全文

與java文件選擇器相關的資料

熱點內容
紅塔銀行app怎麼樣 瀏覽:562
農行app怎麼開網銀 瀏覽:649
java迭代器遍歷 瀏覽:301
閩政通無法請求伺服器是什麼 瀏覽:48
怎麼做積木解壓神器 瀏覽:203
王者榮耀解壓玩具抽獎 瀏覽:49
12位是由啥加密的 瀏覽:868
程序員編迷你世界代碼 瀏覽:895
php取現在時間 瀏覽:246
單片機高吸收 瀏覽:427
怎麼區分五代頭是不是加密噴頭 瀏覽:244
hunt測試伺服器是什麼意思 瀏覽:510
2013程序員考試 瀏覽:641
畢業論文是pdf 瀏覽:736
伺服器跑網心雲劃算嗎 瀏覽:471
單片機定時器計數初值的計算公式 瀏覽:801
win7控制台命令 瀏覽:567
貓咪成年app怎麼升級 瀏覽:692
360有沒有加密軟體 瀏覽:315
清除cisco交換機配置命令 瀏覽:751