List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter
public FileNameExtensionFilter(String description, String... extensions)
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);// w w w .java 2 s .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 www.j av a2 s. c o m }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton loadButton = new JButton("Display Image"); loadButton.addActionListener(ev -> { JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.addChoosableFileFilter(/*ww w . jav a2s . co m*/ new FileNameExtensionFilter("Image files", new String[] { "png", "jpg", "jpeg", "gif" })); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { Image image = ImageIO.read(fc.getSelectedFile()); if (image != null) { JPanel panel = new JPanel(new BorderLayout(10, 10)); panel.add(new JLabel(fc.getSelectedFile().toString()), BorderLayout.NORTH); panel.add(new JLabel(new ImageIcon(image))); JOptionPane.showMessageDialog(frame, panel); } } catch (Exception ex) { ex.printStackTrace(); } } }); frame.add(loadButton); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setSize(300, 500);// www. j a v a2s . com f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pan = new JPanel(new GridLayout(1, 1)); XmlJTree myTree = new XmlJTree(null); f.add(new JScrollPane(myTree)); JButton button = new JButton("Choose file"); button.addActionListener(e -> { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { myTree.setPath(chooser.getSelectedFile().getAbsolutePath()); } }); pan.add(button); f.add(pan, BorderLayout.SOUTH); f.setVisible(true); }
From source file:de.dakror.jagui.parser.NGuiParser.java
public static void main(String[] args) { try {/*from www . j a v a 2 s .c om*/ DIR.mkdirs(); if (!new File(DIR, "convert.exe").exists()) Helper.copyInputStream(NGuiParser.class.getResourceAsStream("/res/convert.exe"), new FileOutputStream(new File(DIR, "convert.exe"))); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JFileChooser jfc = new JFileChooser( new File(NGuiParser.class.getProtectionDomain().getCodeSource().getLocation().toURI())); jfc.setMultiSelectionEnabled(false); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(new FileNameExtensionFilter("Unity ngui Gui-Skin (*.guiskin)", "guiskin")); if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { p("Collecting GUIDs, Converting Resources"); HashMap<String, File> guids = collectGUIDs(jfc.getCurrentDirectory()); p("Parsing Guiskin file"); String s = Helper.getFileContent(jfc.getSelectedFile()); String[] lines = s.split("\n"); ArrayList<String> l = new ArrayList<>(Arrays.asList(lines)); String string = ""; for (int i = 0; i < l.size(); i++) if (!l.get(i).startsWith("%") && !l.get(i).startsWith("---")) string += l.get(i) + "\n"; Yaml yaml = new Yaml(); for (Iterator<Object> iter = yaml.loadAll(string).iterator(); iter.hasNext();) { JSONObject o = new JSONObject((Map<?, ?>) iter.next()); p("Cconverting Guiskin"); replaceGuidDeep(o, guids, jfc.getSelectedFile()); p("Writing converted file"); Helper.setFileContent(new File(jfc.getSelectedFile().getParentFile(), jfc.getSelectedFile().getName() + ".json"), o.toString(4)); p("DONE"); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static JFileChooser getFileChooser() { chooser.setFileFilter(new FileNameExtensionFilter("xml file", "xml")); chooser.setSelectedFile(new File("")); chooser.cancelSelection();/* ww w . ja v a 2 s. com*/ return chooser; }
From source file:Main.java
/** * //from ww w . ja v a 2 s .com * @param owner * @return El directorio seleccionado */ public static File saveFileChooser(Window owner) { int userResponse; JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML", "xml"); fileChooser.setFileFilter(filter); userResponse = fileChooser.showSaveDialog(owner); if (JFileChooser.APPROVE_OPTION == userResponse) { return fileChooser.getSelectedFile(); } return null; }
From source file:Main.java
private static JFileChooser getXMLfileChooser() { JFileChooser fc = new JFileChooser(new File("../comportamientos")); // set ExtensionFile... fc.setMultiSelectionEnabled(false);//from w w w . j ava 2 s. c o m fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML", "xml"); fc.setFileFilter(filter); return fc; }
From source file:Main.java
/** * Gets a text file chooser. Only files with the extension ".txt" and directories are shown. * * @return the file chooser/*www .j a v a2 s . c o m*/ */ public static JFileChooser getTextFileChooser() { final JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files", "txt"); chooser.setFileFilter(filter); return chooser; }
From source file:net.fabricmc.installer.installer.LocalVersionInstaller.java
public static void install(File mcDir, IInstallerProgress progress) throws Exception { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(Translator.getString("install.client.selectCustomJar")); fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar")); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File inputFile = fc.getSelectedFile(); JarFile jarFile = new JarFile(inputFile); Attributes attributes = jarFile.getManifest().getMainAttributes(); String mcVersion = attributes.getValue("MinecraftVersion"); Optional<String> stringOptional = ClientInstaller.isValidInstallLocation(mcDir, mcVersion); jarFile.close();//from ww w.j a v a2 s . c om if (stringOptional.isPresent()) { throw new Exception(stringOptional.get()); } ClientInstaller.install(mcDir, mcVersion, progress, inputFile); } else { throw new Exception("Failed to find jar"); } }