create folder chooser

Ads

 
 

Share on Google+Share on Google+

mac ngoc cthan
create folder chooser
1 Answer(s)      8 years ago
Posted in : Java Server Faces Questions
Ads
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

Ads









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
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
Folder in Java.
Folder in Java.  I have any problem how to make Folder in java program? Can Anybody help me in this part
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
"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
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
create
create  how to create an excel file using java
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
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
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
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
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
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
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
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
Java- Save Image into project folder in web application
want to save the image..when I am trying to create empty folder and get...Java- Save Image into project folder in web application  I have a requirement of saving the image into project folder .. which is a web application
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

Ads

 
Advertisement null

Ads