Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSF-Questions create folder chooser
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mac ngoc cthan
create folder chooser
1 Answer(s)      5 years ago
Posted in : Java Server Faces Questions



Advertisement
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
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
"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
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
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 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 backup files and folder with Java
how to backup files and folder with Java  Does anyone know to create...[]) { CreateBackupFile create = new CreateBackupFile(); String fileName = "C:\\Documents and Settings\\bharat\\Desktop\\bipul\\New Folder\\TableExample.java
Java get Folder Size
in the specified folder. We have create a method getFileSize() in order to obtain... Java get Folder Size     ... of specified folder.  In the given example, we are going to show you the size
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
Full path of image to save it in a folder
&trying to create a project.   Hi, If you wish to upload files in the local context of your project, then you may first create a folder under WEB... are a beginner, I would suggest that you create a servlet and call it from the page using
create
create  how to create an excel file using java
how to download a file from a folder??
how to download a file from a folder??  i can upload any kind of files to a folder, and only the path of the file is saved into the database, now how a client can download the file from my folder. pls provide me the jsp code
search for particular keyword in the folder documents
search for particular keyword in the folder documents  i am having... to particular folder. it is a stand alone application so i have to search particular keyword in the folder having document like in pdf , word or excel
PHP saying folder does not exist
PHP saying folder does not exist  This PHP code is supposed to check if a folder exists based on the value of the URL perimeter ?username= <?php.../Office/user/login.html?error=2"); } ?> But it's saying the folder
how to browse folder and directory in jsp
how to browse folder and directory in jsp  how to browse folder and directory in my jsp page.i have done my coding part for browsing directory but dont know how to get files after that.and also i want to show limited directories
Create new file in java
Create new file in java We are going to discuss how to create new file in java. First of all we have create class "CreateFile".and after that we create main method than we use try and catch block. We have created File object
Zip Folder Using Java
; In this example we are going to create a zip folder and all files contained... and sub folders of a folder just to take less space. To do so we create two... first to create "out"  folder and put the files to be zipped
List Information about folder
List Information about folder       This Example shows you how to show folder information. In this code we have used method of Folder class to retrieve information about
Advertisements
 

 

 

DMCA.com