Java Curious ღ
Java Curious ღ

Reputation: 3692

How to make output directory selection panel?

Hi I am trying to make one pane that shows something like windows explorer in my computer. when user complete it's operations, and after that when he want to save edited image at specific place on disk then he can easily select directory from that pane. i want to design something like this :

enter image description here

is it possible to do something like that ? my picture editor looks like :

enter image description here

at right side of editor i want to put something like output directory selection pane.

is anyone know how to do that ?

Upvotes: 2

Views: 153

Answers (4)

trashgod
trashgod

Reputation: 205785

A complete example using JTree is examined in FileBrowser.

jtree image

An alternative using Outline is shown here.

outline image

Upvotes: 6

Ron
Ron

Reputation: 1508

This can be handled with a JFileChooser, sorry if it's not the solution you're looking for

Note: you say choose a directory but I assume you mean that they can name their file

private File selectSaveFile() {
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileNameExtensionFilter("File Type", "txt"));
    fc.setCurrentDirectory(new File(System.getProperty("user.home")));
    int returnVal = fc.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return fc.getSelectedFile();
    }
    //the user didn't click save if we are here
    return null;
}

Upvotes: 2

MadProgrammer
MadProgrammer

Reputation: 347214

Yes its possible. It's basically just JTree.

You will probably want to take a look at File#listRoots, File#isDirectory and File#listFiles.

You'll also want to take a look at How to use trees.

You'll probably also want to take a look at FileSystemView#getSystemIcon which will allow you to look an appropriate icon for the given File

However, it might be simpler to just use a JFileChooser ;)

Upvotes: 5

Daniel Mac
Daniel Mac

Reputation: 382

You could have a look at JFileChooser. You can use this object to open a SaveDialog and get a save path on the local harddisk. Then eventually use an ObjectOutputStream to write a file.

Sample code:

    JFileChooser c = new JFileChooser();
    c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    // Demonstrate "Save" dialog:
    int rVal = c.showSaveDialog(fb);
    if (rVal == JFileChooser.APPROVE_OPTION) {
        System.out.println(c.getSelectedFile().toString());
    }

Upvotes: 2

Related Questions