国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
論壇: Java 中關(guān)于選擇文件夾對話框 ...
Re: Java 中關(guān)于選擇文件夾對話框
默認(rèn)情況下沒有Windows那種豎排的文件夾選擇框,但可以通過FileDialog或JFileChooser設(shè)定參數(shù)令文件選取方式為[文件夾],給您寫了個(gè)小例子。

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class MyFrame extends JFrame implements ActionListener {

/**
*
*/
private static final long serialVersionUID = 1L;

private JFileChooser fileChooser = new JFileChooser(".");

private JButton button = new JButton("打開文件");

public MyFrame() {
this.setTitle("文件夾選擇");
this.setPreferredSize(new Dimension(200, 100));
this.getContentPane().add(button, BorderLayout.NORTH);
button.addActionListener(this);
this.pack();
this.setLocationRelativeTo(null);
this.setIgnoreRepaint(true);
}

public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
// 觸發(fā)JButton(此例僅設(shè)置有一個(gè)按鈕,多按鈕請自行更改)
if (source instanceof JButton) {
openFile();
}

}

public void openFile() {
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setDialogTitle("打開文件夾");
int ret = fileChooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION) {
//文件夾路徑
System.out.println(fileChooser.getSelectedFile().getAbsolutePath());
}
}

public static void main(String[] args) {
Frame frame = new MyFrame();
frame.setVisible(true);
}


}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
VideoPlayDemo
文件選擇對話框,顏色選擇對話框,分隔線的使用與介紹 - JAVA記事 - JavaEye技...
Swing使用JFileChooser選擇文件目錄
設(shè)置背景圖,并在上面添加可隨意拖動(dòng)的圖片標(biāo)簽
Swing文件下載
FileDialog vs JFileChooser
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服