List of usage examples for javax.swing JFileChooser JFileChooser
public JFileChooser(FileSystemView fsv)
JFileChooser
using the given FileSystemView
. From source file:Main.java
Main() { gui.setBorder(new EmptyBorder(2, 3, 2, 3)); String userDirLocation = System.getProperty("user.dir"); File userDir = new File(userDirLocation); // default to user directory fileChooser = new JFileChooser(userDir); Action open = new AbstractAction("Open") { @Override/*from ww w . j a v a 2 s. c om*/ public void actionPerformed(ActionEvent e) { int result = fileChooser.showOpenDialog(gui); if (result == JFileChooser.APPROVE_OPTION) { try { File f = fileChooser.getSelectedFile(); FileReader fr = new FileReader(f); output.read(fr, f); fr.close(); } catch (Exception ex) { ex.printStackTrace(); } } } }; Action save = new AbstractAction("Save") { @Override public void actionPerformed(ActionEvent e) { int result = fileChooser.showSaveDialog(gui); System.out.println("Not supported yet."); } }; JToolBar tb = new JToolBar(); gui.add(tb, BorderLayout.PAGE_START); tb.add(open); tb.add(save); gui.add(new JScrollPane(output)); }
From source file:net.sf.jabref.importer.ImportFormats.java
private static JFileChooser createImportFileChooser(String currentDir) { SortedSet<ImportFormat> importers = Globals.IMPORT_FORMAT_READER.getImportFormats(); String lastUsedFormat = Globals.prefs.get(JabRefPreferences.LAST_USED_IMPORT); FileFilter defaultFilter = null; JFileChooser fc = new JFileChooser(currentDir); Set<ImportFileFilter> filters = new TreeSet<>(); for (ImportFormat format : importers) { ImportFileFilter filter = new ImportFileFilter(format); filters.add(filter);/*from w w w . j a v a2 s . c o m*/ if (format.getFormatName().equals(lastUsedFormat)) { defaultFilter = filter; } } for (ImportFileFilter filter : filters) { fc.addChoosableFileFilter(filter); } if (defaultFilter == null) { fc.setFileFilter(fc.getAcceptAllFileFilter()); } else { fc.setFileFilter(defaultFilter); } return fc; }
From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java
public static void show() throws JSONException { final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true); dialog.setSize(400, 250);// w w w . ja v a 2 s . c o m dialog.setLocationRelativeTo(Server.currentServer.frame); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel cp = new JPanel(new SpringLayout()); cp.add(new JLabel("Zielverzeichnis:")); JPanel panel = new JPanel(); final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path") ? Server.currentServer.settings.getString("backup.path") : ""), 10); panel.add(path); panel.add(new JButton(new AbstractAction("Whlen...") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText()) : new File(System.getProperty("user.home")))); jfc.setFileHidingEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Backup-Zielverzeichnis whlen"); if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) path.setText(jfc.getSelectedFile().getPath().replace("\\", "/")); } })); cp.add(panel); cp.add(new JLabel("")); cp.add(new JLabel("")); cp.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); cp.add(new JButton(new AbstractAction("Speichern") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { if (path.getText().length() > 0) Server.currentServer.settings.put("backup.path", path.getText()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } })); SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6); dialog.setContentPane(cp); dialog.pack(); dialog.setVisible(true); }
From source file:task5.Histogram.java
private void getImage() { String userDir = System.getProperty("user.home"); JFileChooser fileChooser = new JFileChooser(userDir + "/Desktop"); int result = fileChooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try {/*from w w w.j av a 2 s . c om*/ img = ImageIO.read(selectedFile); myframe = get_MYIMAGE(); } catch (IOException ex) { Logger.getLogger(MyImage.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:imageprocessingproject.MainFrame.java
private void initialize() { // file chooser filechooser = new JFileChooser("C:"); filechooser.addChoosableFileFilter(new FileNameExtensionFilter("JPG", "JPG", "JPEG")); filechooser.addChoosableFileFilter(new FileNameExtensionFilter("PNG", "PNG")); filechooser.addChoosableFileFilter(new FileNameExtensionFilter("GIF", "GIF")); filechooser.addChoosableFileFilter(new FileNameExtensionFilter("tt", "tt")); // image handler imageHandler = ImageHandler.getInstance(this); }
From source file:com.mgmtp.perfload.loadprofiles.ui.util.SwingUtils.java
public static JFileChooser createFileChooser(final File dir, final String description, final String extension) { JFileChooser fc = new JFileChooser(dir); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false);//from w w w .j a v a 2 s . com fc.setAcceptAllFileFilterUsed(false); fc.addChoosableFileFilter(new FileFilter() { @Override public String getDescription() { return description; } @Override public boolean accept(final File f) { return f.isDirectory() || FilenameUtils.isExtension(f.getName(), extension); } }); return fc; }
From source file:finalproject.BloodGlucoseGUI.java
/** * Constructor//from w w w .j ava2s. co m * Creates new form BloodGlucoseGUI */ // I would put most of it in initComponents if I could // edit that generated code. public BloodGlucoseGUI() { initComponents(); //jfc = new JFileChooser("Resources/Data"); // For "commercial" use //jfc = new JFileChooser("C:\\Program Files\\BGDataAnalysis\\Data"); jfc = new JFileChooser("C:\\BGDataAnalysis\\Data"); tabMod = new MyTableModel(); jTable2.setModel(tabMod); listMod = new DefaultListModel(); jList1.setModel(listMod); JTableHeader th = jTable2.getTableHeader(); TableColumnModel tcm = th.getColumnModel(); TableColumn tc = tcm.getColumn(0); tc.setHeaderValue("Time"); tc = tcm.getColumn(1); tc.setHeaderValue("Blood Glucose"); th.repaint(); notesTextArea.setLineWrap(true); notesTextArea.setWrapStyleWord(true); notesTextArea.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { e.consume(); ErrorGUIs.Popup pu = new ErrorGUIs.Popup(); pu.add("Please don't press the ENTER button!"); pu.display(); } } }); }
From source file:edu.clemson.lph.civet.addons.VspsCviFile.java
public void importVspsFile(Window parent) { String sVspsDir = CivetConfig.getVspsDirPath(); File fDir = new File(sVspsDir); JFileChooser open = new JFileChooser(fDir); Action details = open.getActionMap().get("viewTypeDetails"); details.actionPerformed(null);/* w w w. jav a2 s . co m*/ open.setDialogTitle("Civet: Open PDF File"); open.setFileSelectionMode(JFileChooser.FILES_ONLY); open.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); open.setMultiSelectionEnabled(false); int resultOfFileSelect = open.showOpenDialog(parent); if (resultOfFileSelect == JFileChooser.APPROVE_OPTION) { File fIn = open.getSelectedFile(); saveme(parent, fIn); // vsps.printme(); } }
From source file:org.pmedv.jake.commands.OpenPlayerViewCommand.java
@Override public void execute() { final ApplicationContext ctx = AppContext.getApplicationContext(); final ApplicationWindow win = (ApplicationWindow) ctx.getBean(BeanDirectory.WINDOW_APPLICATION); /**//ww w . j a va2 s.c o m * Get last selected folder to simplify file browsing */ if (AppContext.getLastSelectedFolder() == null) AppContext.setLastSelectedFolder(System.getProperty("user.home")); JFileChooser fc = new JFileChooser(AppContext.getLastSelectedFolder()); fc.setDialogTitle("Open directory"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fc.showOpenDialog(win); if (result == JFileChooser.CANCEL_OPTION) return; AppContext.setLastSelectedFolder(fc.getSelectedFile().getAbsolutePath()); List<File> files = new ArrayList<File>(); FileUtils.findFile(files, fc.getSelectedFile(), ".mp3", true, true); final PlayerController controller = new PlayerController(files); JakeUtil.updateRecentFiles(fc.getSelectedFile().getAbsolutePath()); View view = new View(fc.getSelectedFile().getAbsolutePath(), null, controller.getPlayerView()); view.addListener(new DockingWindowAdapter() { @Override public void windowClosing(DockingWindow arg0) throws OperationAbortedException { if (controller.getPlayer() != null) controller.getPlayer().close(); controller.getPlayFileCommand().setPlaying(false); } }); openEditor(view); }
From source file:net.menthor.editor.v2.util.Util.java
public static JFileChooser createChooser(String lastPath, final boolean checkOverrideFile) { return new JFileChooser(lastPath) { private static final long serialVersionUID = 1L; @Override//ww w.j a v a 2 s . c om public void approveSelection() { File f = getSelectedFile(); if (f.exists() && checkOverrideFile) { int result = JOptionPane.showConfirmDialog(this, "\"" + f.getName() + "\" already exists. Do you want to overwrite it?", "Existing file", JOptionPane.YES_NO_CANCEL_OPTION); switch (result) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: return; case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: cancelSelection(); return; } } super.approveSelection(); } }; }