List of usage examples for javax.swing JFileChooser APPROVE_OPTION
int APPROVE_OPTION
To view the source code for javax.swing JFileChooser APPROVE_OPTION.
Click Source Link
From source file:Main.java
public static void main(String s[]) { JFileChooser chooser = new JFileChooser(); int rc = chooser.showOpenDialog(null); while (rc == JFileChooser.APPROVE_OPTION && !chooser.getSelectedFile().getName().endsWith(".java")) { JOptionPane.showMessageDialog(null, "The file " + chooser.getSelectedFile() + " is not java source file.", "Open Error", JOptionPane.ERROR_MESSAGE); rc = chooser.showOpenDialog(null); }/*w w w .ja va 2s. c o m*/ }
From source file:Main.java
public static void main(String[] argv) { JFileChooser chooser = new JFileChooser(); int result = chooser.showOpenDialog(null); switch (result) { case JFileChooser.APPROVE_OPTION: System.out.println("Approve (Open or Save) was clicked"); break;//from ww w . ja v a 2 s .com case JFileChooser.CANCEL_OPTION: System.out.println("Cancel or the close-dialog icon was clicked"); break; case JFileChooser.ERROR_OPTION: System.out.println("Error"); break; } }
From source file:Main.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser("."); int status = fileChooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = fileChooser.getSelectedFiles(); } else if (status == JFileChooser.CANCEL_OPTION) { System.out.println("canceled"); }/*from w w w .ja v a 2 s .c o m*/ }
From source file:JFileChooserSelectionOption.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser("."); int status = fileChooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println(selectedFile.getParent()); System.out.println(selectedFile.getName()); } else if (status == JFileChooser.CANCEL_OPTION) { System.out.println("canceled"); }//from w w w. j a v a2 s.c om }
From source file:Main.java
public static void main(String[] args) throws Exception { JFileChooser fileChooser = new JFileChooser(); int a = fileChooser.showOpenDialog(null); if (a == JFileChooser.APPROVE_OPTION) { File fileToOpen = fileChooser.getSelectedFile(); Desktop.getDesktop().open(fileToOpen); }/*from w w w.j a v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { // Display an open file chooser JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println("we selected: " + selectedFile); }//from w w w . j ava2s. c om }
From source file:Main.java
public static void main(String[] args) { String text = "JFileChooser, you're my only friend."; JFileChooser chooser = new JFileChooser(); int result = chooser.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { try {//from ww w .j a va 2s . c o m File file = chooser.getSelectedFile(); FileWriter writer = new FileWriter(file); writer.write(text); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:Main.java
public static void main(String s[]) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("choosertitle"); 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 {// ww w . ja va 2s . c o m System.out.println("No Selection "); } }
From source file:MainClass.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser("."); fileChooser.setAccessory(new LabelAccessory(fileChooser)); int status = fileChooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println(selectedFile.getParent()); System.out.println(selectedFile.getName()); } else if (status == JFileChooser.CANCEL_OPTION) { System.out.println("JFileChooser.CANCEL_OPTION"); }//from w w w . j a v a 2s . c o m }
From source file:FileChooserDialog.java
public static void main(String[] args) { JFileChooser fileopen = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("c files", "c"); fileopen.addChoosableFileFilter(filter); int ret = fileopen.showDialog(null, "Open file"); if (ret == JFileChooser.APPROVE_OPTION) { File file = fileopen.getSelectedFile(); System.out.println(file); }//from w w w . j av a2s . com }