List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:Main.java
public static void main(String[] args) { JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(null); }
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); }/*from ww w . j ava 2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { Image image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB); JFrame f = new JFrame(); f.setIconImage(image);//from ww w . j a v a 2s . c o m f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setSize(600, 400); f.setVisible(true); JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(f); }
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 www .java 2 s. 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 w w w .j a va 2s. c o m*/ 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"); }/* www .j av a 2s. 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 ww w . j a v a2 s . c om }
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 . ja v a 2 s .co m }
From source file:Main.java
public static void main(String[] args) { String path = System.getProperty("user.dir", "."); File dir = new File(path); JFileChooser jfc = new JFileChooser(dir); int result = jfc.showOpenDialog(null); switch (result) { case JFileChooser.CANCEL_OPTION: System.out.println("User cancelled OPEN dialog."); break;/*ww w .j a v a2s . co m*/ case JFileChooser.APPROVE_OPTION: System.out.println("User chose file: " + jfc.getSelectedFile()); break; case JFileChooser.ERROR_OPTION: System.out.println("User encountered an error"); break; default: System.out.println("Confused"); break; } System.exit(0); }
From source file:Main.java
public static void main(String[] argv) { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.showOpenDialog(null); File[] files = chooser.getSelectedFiles(); }