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[] argv) throws Exception { JFileChooser chooser = new JFileChooser(); File f = new File(new File(".").getCanonicalPath()); chooser.setCurrentDirectory(f);/* www.j a v a2 s . c o m*/ chooser.setCurrentDirectory(null); chooser.showOpenDialog(null); File curDir = chooser.getCurrentDirectory(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFileChooser chooser = new JFileChooser(); File f = new File(new File(".").getCanonicalPath()); chooser.setCurrentDirectory(f);/* w w w . jav a 2 s . c o m*/ chooser.setCurrentDirectory(null); chooser.showOpenDialog(null); FileFilter obj = chooser.getAcceptAllFileFilter(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFileChooser chooser = new JFileChooser(); File f = new File(new File(".").getCanonicalPath()); chooser.setCurrentDirectory(f);//from ww w . j a va 2 s. c o m chooser.setCurrentDirectory(null); chooser.showOpenDialog(null); AccessibleContext obj = chooser.getAccessibleContext(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFileChooser chooser = new JFileChooser(); File f = new File(new File(".").getCanonicalPath()); chooser.setCurrentDirectory(f);/*from w ww.j a va 2 s .c om*/ chooser.setCurrentDirectory(null); chooser.showOpenDialog(null); JComponent obj = chooser.getAccessory(); }
From source file:MainClass.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser("."); FileView view = new JavaFileView(); fileChooser.setFileView(view);//from www . jav a2s. c o m 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 source file:DesktopDemo.java
public static void main(String[] args) { if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); } else {//from w ww.j a v a 2 s. co m System.out.println("Desktop class is not supported"); System.exit(1); } JMenuItem openItem = new JMenuItem("Open"); JMenuItem editItem = new JMenuItem("Edit"); JMenuItem printItem = new JMenuItem("Print"); JMenuItem browseToItem = new JMenuItem("Go to www.java2s.com"); JMenuItem mailToItem = new JMenuItem("Email to a@java.com"); JMenu fileMenu = new JMenu("File"); JMenu mailMenu = new JMenu("Email"); JMenu browseMenu = new JMenu("Browser"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { desktop.open(chooser.getSelectedFile().getAbsoluteFile()); } catch (Exception ex) { ex.printStackTrace(); } } } }); fileMenu.add(openItem); editItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { desktop.edit(chooser.getSelectedFile().getAbsoluteFile()); } catch (Exception ex) { ex.printStackTrace(); } } } }); fileMenu.add(editItem); printItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { desktop.print(chooser.getSelectedFile().getAbsoluteFile()); } catch (Exception ex) { ex.printStackTrace(); } } } }); fileMenu.add(printItem); browseToItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { URI browseURI = new URI("www.java2s.com"); desktop.browse(browseURI); } catch (Exception ex) { System.out.println(ex.getMessage()); } } }); browseMenu.add(browseToItem); mailToItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { URI mailURI = new URI("mailto:support@java.com"); desktop.mail(mailURI); } catch (Exception ex) { System.out.println(ex.getMessage()); } } }); mailMenu.add(mailToItem); JMenuBar jMenuBar = new JMenuBar(); jMenuBar.add(fileMenu); jMenuBar.add(browseMenu); jMenuBar.add(mailMenu); JFrame frame = new JFrame(); frame.setTitle("Desktop Helper Applications"); frame.setSize(300, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(jMenuBar); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFileChooser fileChooser = new JFileChooser("."); fileChooser.setControlButtonsAreShown(false); fileChooser.setFileFilter(new FolderFilter()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.showOpenDialog(null); }
From source file:Main.java
public static void main(String[] args) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("MPEG3 songs", "mp3"); fileChooser.addChoosableFileFilter(filter); fileChooser.showOpenDialog(null); }
From source file:ExtensionFileFilter.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser("."); FileFilter jpegFilter = new ExtensionFileFilter(null, new String[] { "JPG", "JPEG" }); fileChooser.addChoosableFileFilter(jpegFilter); fileChooser.showOpenDialog(null); }
From source file:Main.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser("."); FileFilter filter1 = new ExtensionFileFilter("JPG and JPEG", new String[] { "JPG", "JPEG" }); fileChooser.setFileFilter(filter1);/*from ww w .j a v a 2 s . c om*/ 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); } }