create folder chooser

create folder chooser

View Answers

October 28, 2009 at 5:01 PM

Hi Friend,

Try the following codes:
1)
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;


public class ChooseFolder {

public static void main(String s[]) {

JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("Save");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): "
+ chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : "
+ chooser.getSelectedFile());
}
else {
System.out.println("No Selection ");
}
}

}
2)
import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.ImageIO;

public class SaveImage extends Component {
int index;
BufferedImage bi, bufferImage;
int w, h;
static JButton button;

public SaveImage() {
try {
bi = ImageIO.read(new File("node.jpg"));
w = bi.getWidth(null);
h = bi.getHeight(null);
if (bi.getType() != BufferedImage.TYPE_INT_RGB) {
BufferedImage bi2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics big = bi2.getGraphics();
big.drawImage(bi, 0, 0, null);
bufferImage = bi = bi2;
}
} catch (IOException e) {
System.out.println("Image could not be read");
System.exit(1);
}
button=new JButton("Save");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
File saveFile = new File("image." + "jpg");
JFileChooser chooser = new JFileChooser();
chooser.setSelectedFile(saveFile);
int val = chooser.showSaveDialog(button);
if (val == JFileChooser.APPROVE_OPTION) {
saveFile = chooser.getSelectedFile();
try {
ImageIO.write(bufferImage, "jpg", saveFile);
} catch (IOException ex) {
}
}
}
});
}
public Dimension getPreferredSize() {
return new Dimension(w, h);
}
public void paint(Graphics g) {
filterImage();
g.drawImage(bufferImage, 0, 0, null);
}
public void filterImage(){
BufferedImageOp op = null;
switch (index){
case 0:
bufferImage = bi;
return;
case 1:
}
bufferImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
op.filter(bi, bufferImage);
}
public static void main(String s[]) {
JFrame f = new JFrame("Save Image");
SaveImage si = new SaveImage();
f.add("Center", si);
JPanel panel = new JPanel();
panel.add(button);
f.add("South", panel);
f.pack();
f.setVisible(true);
}
}
Hope that the codes will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
create folder chooser - Java Server Faces Questions
create folder chooser  I don't know how to create a browser folder( to save file download, for instance, not file chooser), please help me,(use swing...[]) { JFileChooser chooser = new JFileChooser
create folder
create folder  what code we should write as a web application that it create an empty folder on client's desktop
Advertisements
create a folder in jsp page
create a folder in jsp page  i want to create a folder in jsp page And it can be delete aslo
ModuleNotFoundError: No module named 'create-folder'
ModuleNotFoundError: No module named 'create-folder'  Hi, My... 'create-folder' How to remove the ModuleNotFoundError: No module named 'create-folder' error? Thanks   Hi, In your python
Directory chooser in core java - Java Beginners
Directory chooser in core java  Hi, I have to create a Utility which will copy files from a source folder to the any other folder. For same I want to create a GUI( AWT or Swing based only) which should have 2 directory
ModuleNotFoundError: No module named 'chooser'
ModuleNotFoundError: No module named 'chooser'  Hi, My Python... 'chooser' How to remove the ModuleNotFoundError: No module named 'chooser... to install padas library. You can install chooser python with following command
ModuleNotFoundError: No module named 'chooser'
ModuleNotFoundError: No module named 'chooser'  Hi, My Python... 'chooser' How to remove the ModuleNotFoundError: No module named 'chooser... to install padas library. You can install chooser python with following command
Folder in Java.
Folder in Java.  I have any problem how to make Folder in java program? Can Anybody help me in this part
ModuleNotFoundError: No module named 'bar-chooser'
ModuleNotFoundError: No module named 'bar-chooser'  Hi, My Python... 'bar-chooser' How to remove the ModuleNotFoundError: No module named 'bar-chooser' error? Thanks   Hi, In your python environment
Java lock file or folder.
Java lock file or folder.  Is it possible to create a desktop application to lock or encrypt file or folder in windows by using java code?? if possible can provide some reference?? because i can't find it... thanks
how to set folder size in php
how to set folder size in php  hi , i know how to create folder but i dont know how to set size for folder did u know means tell me. thankyour
Version of com.kbeanie>image-chooser-library dependency
List of Version of com.kbeanie>image-chooser-library dependency
Version of com.robbypond>image-chooser-library dependency
List of Version of com.robbypond>image-chooser-library dependency
ModuleNotFoundError: No module named 'lektor-mathshistory-chooser'
ModuleNotFoundError: No module named 'lektor-mathshistory-chooser'  ...: No module named 'lektor-mathshistory-chooser' How to remove the ModuleNotFoundError: No module named 'lektor-mathshistory-chooser' error? Thanks
ModuleNotFoundError: No module named 'wagtail-generic-chooser'
ModuleNotFoundError: No module named 'wagtail-generic-chooser'  Hi...: No module named 'wagtail-generic-chooser' How to remove the ModuleNotFoundError: No module named 'wagtail-generic-chooser' error? Thanks   
ModuleNotFoundError: No module named 'djangocms-lang-chooser'
ModuleNotFoundError: No module named 'djangocms-lang-chooser'  Hi...: No module named 'djangocms-lang-chooser' How to remove the ModuleNotFoundError: No module named 'djangocms-lang-chooser' error? Thanks   Hi
ModuleNotFoundError: No module named 'gtk-file-chooser'
ModuleNotFoundError: No module named 'gtk-file-chooser'  Hi, My... named 'gtk-file-chooser' How to remove the ModuleNotFoundError: No module named 'gtk-file-chooser' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'lektor-mathshistory-chooser'
ModuleNotFoundError: No module named 'lektor-mathshistory-chooser'  ...: No module named 'lektor-mathshistory-chooser' How to remove the ModuleNotFoundError: No module named 'lektor-mathshistory-chooser' error? Thanks
ModuleNotFoundError: No module named 'gtk-file-chooser'
ModuleNotFoundError: No module named 'gtk-file-chooser'  Hi, My... named 'gtk-file-chooser' How to remove the ModuleNotFoundError: No module named 'gtk-file-chooser' error? Thanks   Hi, In your
"The folder name is not valid" netbeans
"The folder name is not valid" netbeans  "The folder name is not valid" while crating a jsp,html or any page in netbeans
create
create  how to create an excel file using java
Maven Repository/Dependency: com.robbypond | image-chooser-library
Maven Repository/Dependency of Group ID com.robbypond and Artifact ID image-chooser-library. Latest version of com.robbypond:image-chooser-library dependencies...? How to create Maven Web Application in Eclipse? Maven 3 Tutorial
copy file from folder to folder - Java Beginners
copy file from folder to folder   my requirement is I need to copy xml files from one folder to another my source file contains the field filename.... Suppose in the source file, file name is goodfile1.xml source folder
struts2 folder struture - Struts
struts2 folder struture  Hi, I just want to know the exact folder structure required for the struts2 application? Its urgent
Zipping folder - Java Beginners
to zip a user selected folder . this folder may contain any number of folder and sub folders. i saw an example in this site showing , how to zip a folder, i executed... solve this.. zipping folder and all of its files and sub folders. thanking
How I Choose a folder - Java Interview Questions
do not explain clearly my question. I know how I get files from a folder. My question How I select a folder. From this selected folder i get the files. I know how I get files but the problem How I choose a folder. Thanks
com.kbeanie - image-chooser-library version 1.4.01 Maven dependency. How to use image-chooser-library version 1.4.01 in pom.xml?
com.kbeanie  - Version 1.4.01 of image-chooser-library Maven dependency? How to use  com.kbeanie  - Version 1.4.01 of image-chooser-library in pom.xml? How to use image-chooser-library version 1.4.01 in pom.xml? Learn
Last modified date of a folder
Last modified date of a folder  How to get the last modified date of a folder specified by a link in html
URL folder download to local
URL folder download to local  I have a requirement to download all the folders and files inside from a SVN link to my local directory. Can you help how it could be done
java program to copy the contents of one folder to another folder
java program to copy the contents of one folder to another folder  java program to copy the contents of one folder to another folder   Have a look at the following link: Java Copy one folder to another
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open... folder and that path stored into database, for furhter retrivation. Please guide me
Zipping folder - Java Beginners
to zip a user selected folder . this folder may contain any number of folder and sub folders. i saw an example in this site showing , how to zip a folder, i executed... solve this.. zipping folder and all of its files and sub folders. thanking
linux tar folder and subfolders
linux tar folder and subfolders  Hi, I am new to Linux operating system. I have a directory which contains many files in several directories and sub.... Help me with the command in Linux for archiving folder and subfolders into tar
xcode group folder
in Xcode Project Folder. Neelam   Follow the steps.. View -> Smart Groups -> All Files it'll group all the files in Xcode Project Folder. Neelam
How to make a folder icon, make a folder icon, folder icon
How to make a folder icon       The folder is used in the computer, this example will teach you to design technique of the folder.  New File: Take a new file as your folder
Maven Dependency image-chooser-library >> 1.3.4
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.3.4 in your project
Maven Dependency image-chooser-library >> 1.5.2
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.5.2 in your project
Maven Dependency image-chooser-library >> 1.5.8
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.5.8 in your project
Maven Dependency image-chooser-library >> 1.4.02
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.4.02 in your project
Maven Dependency image-chooser-library >> 1.5.5
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.5.5 in your project
Maven Dependency image-chooser-library >> 1.3.3
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.3.3 in your project
Maven Dependency image-chooser-library >> 1.3.54
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.3.54 in your project
Maven Dependency image-chooser-library >> 1.4.01
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.4.01 in your project
Maven Dependency image-chooser-library >> 1.5.1
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.5.1 in your project
Maven Dependency image-chooser-library >> 1.4.5-beta
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.4.5-beta in your project
Maven Dependency image-chooser-library >> 1.5.6
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.5.6 in your project
Maven Dependency image-chooser-library >> 1.3.53
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.3.53 in your project
Maven Dependency image-chooser-library >> 1.4.3
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.4.3 in your project
Maven Dependency image-chooser-library >> 1.5.4
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.5.4 in your project
Maven Dependency image-chooser-library >> 1.3.51
You should include the dependency code given in this page to add Maven Dependency of com.kbeanie >> image-chooser-library version1.3.51 in your project

Ads