开发者

How to get required folder URL using java swings?

I am using Netbeans for java application. during my application at one point i want particular开发者_Python百科 folder URL to store files. how can i achieve this. please can anyone help me..

Thanks in advance :)


Use a JFileChooser, with JFileChooser.DIRECTORIES_ONLY Take a look at this tutorial: How to Use File Choosers

JFileChooser chooser = new JFileChooser(); 
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);


You want to select a folder in a swing application, right? you can use JFileChooser http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html

to select only a folder, look at this example http://www.rgagnon.com/javadetails/java-0370.html

for the saving, check http://download.oracle.com/javase/tutorial/essential/io/file.html

if you need something clarified, just ask.


I guess you want a Open File Dialog box.
In Swing it is called JFileChooser.

Usage example:

JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(yourJFrame);

if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    // Do stuff with file
} else {
    // User clicked cancel
}

yourJFrame should be the JFrame you use for your main window. If you don't have one put null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜