aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes file chooser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "file chooser" Watch "file chooser" New topic
Author

file chooser

trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
using JFileChhoser we can select a file.in that way can we open a directory.if so please tell me how to do this
Vasu Reddy
Ranch Hand

Joined: Sep 13, 2005
Posts: 32
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;


public class DemoJFileChooser extends JPanel
implements ActionListener {
JButton go;

JFileChooser chooser;
String choosertitle;

public DemoJFileChooser() {
go = new JButton("Do it");
go.addActionListener(this);
add(go);
}

public void actionPerformed(ActionEvent e) {
int result;

chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
}
else {
System.out.println("No Selection ");
}
}

public Dimension getPreferredSize(){
return new Dimension(200, 200);
}

public static void main(String s[]) {
JFrame frame = new JFrame("");
DemoJFileChooser panel = new DemoJFileChooser();
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
frame.getContentPane().add(panel,"Center");
frame.setSize(panel.getPreferredSize());
frame.setVisible(true);
}
}


Hope you get idea, how to do.

Regards,

Vasu
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Starter/Vasu,

Welcome to JavaRanch!

Hi,

Welcome to JavaRanch!

A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Joke names, "nicks" and "handles" aren't acceptable here. You can change your display name here. Thanks for your prompt cooperation.


[Jess in Action][AskingGoodQuestions]
Vasu Reddy
Ranch Hand

Joined: Sep 13, 2005
Posts: 32
Thanks for letting me know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file chooser