List of usage examples for javax.swing JFileChooser setFileSelectionMode
@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY", "JFileChooser.DIRECTORIES_ONLY", "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode)
JFileChooser
to allow the user to just select files, just select directories, or select both files and directories. From source file:Main.java
public static void main(String[] argv) { JFileChooser fileChooser = new JFileChooser("."); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); }
From source file:Main.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.showSaveDialog(null);//from www. ja v a 2s . c o m }
From source file:Main.java
public static void main(String[] a) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.showOpenDialog(null);//from ww w.j a v a2s. com }
From source file:AudioFilter.java
public static void main(String[] args) { AudioFilter audioFilter = new AudioFilter(); JFileChooser jfc = new JFileChooser(); jfc.setDialogTitle("Open File"); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setCurrentDirectory(new File(".")); jfc.setFileFilter(audioFilter);/* ww w.j a va2s.co m*/ int result = jfc.showOpenDialog(null); if (result == JFileChooser.CANCEL_OPTION) { System.out.println("cancel"); } else if (result == JFileChooser.APPROVE_OPTION) { File fFile = jfc.getSelectedFile(); String filestr = fFile.getAbsolutePath(); System.out.println(filestr); } }
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 {//from w ww . j a v a 2s . c o m System.out.println("No Selection "); } }
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 w w w . j a v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); final JButton button = new JButton("Select files..."); button.addActionListener(e -> {/*from w w w .j a va 2 s . c om*/ final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(chooser.getFileSystemView().getParentDirectory(new File("C:\\"))); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.showDialog(button, "Select file"); }); panel.add(button); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:com.acmutv.ontoqa.GrammalexMain.java
/** * The app main method, executed when the program is launched. * @param args The command line arguments. * @throws IllegalAccessException /*from w w w .j av a 2 s . c o m*/ * @throws InstantiationException */ public static void main(String[] args) throws InstantiationException, IllegalAccessException { //CliService.handleArguments(args); RuntimeManager.registerShutdownHooks(new ShutdownHook()); try { Path path = FileSystems.getDefault().getPath("data/lexicon").toAbsolutePath(); String currentDirectory = path.toString(); final JFileChooser fc = new JFileChooser(currentDirectory); int returnVal = fc.showOpenDialog(null); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); if (returnVal == JFileChooser.OPEN_DIALOG) { File file = fc.getSelectedFile(); System.out.println("File Select: " + file.getName() + "\n\n"); List<LexicalEntry> lEntries = LexiconUsage.getLexicalEntries(file.getAbsolutePath(), "", LexiconFormat.RDFXML); Grammar grammar = SerializeSltag.getAllElementarySltag(lEntries); SerializeSltag.writeGrammarOnFile(grammar, fileJson); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.exit(0); }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
public static void main(String[] args) { JFrame frame = new JFrame("RedstoneLamp"); frame.setLayout(new GridLayout(2, 1)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel label = new JLabel("RedstoneLamp"); label.setHorizontalAlignment(SwingConstants.CENTER); frame.add(label);// w ww.j a va2 s . c o m JPanel lowPanel = new JPanel(); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); lowPanel.add(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); lowPanel.add(right); JButton openButton = new JButton("Open server at..."); openButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Select RedstoneLamp server home"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showOpenDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (!jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. " + "Would you like to install RedstoneLamp there?"); if (result == JOptionPane.YES_OPTION) { installCallback(frame, selected); } return; } frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); } }); right.add(openButton); JButton installButton = new JButton("Install server at..."); installButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser("."); chooser.setDialogTitle("Select directory to install server in"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showSaveDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. " + "Are you sure you want to reinstall RedstoneLamp there?"); if (result == JOptionPane.NO_OPTION) { frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); return; } } installCallback(frame, selected); } }); frame.add(lowPanel); frame.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dimension.width / 2 - frame.getSize().width / 2, dimension.height / 2 - frame.getSize().height / 2); frame.setVisible(true); }
From source file:de.dakror.jagui.parser.NGuiParser.java
public static void main(String[] args) { try {/*from w ww . jav a2s .c o m*/ 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(); } }