List of usage examples for javax.swing JFileChooser JFileChooser
public JFileChooser()
JFileChooser
pointing to the user's default directory. From source file:de.burrotinto.jKabel.dbauswahlAS.DBAuswahlAAS.java
private String choosePath(String pfad) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(pfad)); chooser.setDialogTitle("DB Pfad"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); return chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION ? null : chooser.getSelectedFile().getPath() + File.separator; }
From source file:br.com.elotech.sits.config.dialog.ChooseFileDialog.java
private void buildFileChooser() { getContentPane().add(fileChooser = new JFileChooser()); fileChooser.setFileFilter(buildKeyStoreFileFilter()); fileChooser.addActionListener(this); }
From source file:net.sf.housekeeper.swing.ExportShoppingListCommand.java
public ExportShoppingListCommand() { super("exportShoppingListCommand"); setEnabled(true);//from ww w . java 2s . c o m chooser = new JFileChooser(); chooser.setSelectedFile(new File("shopping_list.txt")); addCommandInterceptor(new ErrorInterceptor()); }
From source file:eu.apenet.dpt.standalone.gui.XsdAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsdChooser = new JFileChooser(); xsdChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsdChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsdChooser.getSelectedFile(); if (isXSD(file)) { XsdInfoQueryComponent xsdInfoQueryComponent = new XsdInfoQueryComponent(labels, file.getName()); int result = JOptionPane.showConfirmDialog(parent, xsdInfoQueryComponent, "title", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { if (StringUtils.isEmpty(xsdInfoQueryComponent.getName())) { errorMessage();/*from w ww . ja v a2s . com*/ } else { if (saveXsd(file, xsdInfoQueryComponent.getName(), false, xsdInfoQueryComponent.getXsdVersion(), xsdInfoQueryComponent.getFileType())) { JRadioButton newButton = new JRadioButton(xsdInfoQueryComponent.getName()); newButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXsd().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsdPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsdPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsdSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { errorMessage(); } } } } else { errorMessage(); } } }
From source file:examples.gp.monalisa.gui.GeneticDrawingView.java
@Action public void chooseImage() throws IOException { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(".")); fc.showOpenDialog(mainPanel);/*w ww . ja va 2 s . c o m*/ File file = fc.getSelectedFile(); targetImage = ImageIO.read(file); targetImageLabel.setIcon(scaleToImageLabel(targetImage)); fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight()); }
From source file:net.panthema.BispanningGame.MyGraphMLReader.java
MyGraphMLReader(javax.swing.JPanel panel) throws FileNotFoundException, GraphIOException { posMap = new TreeMap<Integer, Point2D>(); // Query user for filename JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Specify GraphML file to read"); chooser.setCurrentDirectory(new File(".")); FileNameExtensionFilter filter = new FileNameExtensionFilter("GraphML File", "graphml"); chooser.setFileFilter(filter);/* ww w. j a va 2 s . co m*/ if (chooser.showOpenDialog(panel) != JFileChooser.APPROVE_OPTION) return; File infile = chooser.getSelectedFile(); BufferedReader fileReader = new BufferedReader(new FileReader(infile)); newGraph = new MyGraph(); // create the graph transformer Transformer<GraphMetadata, MyGraph> graphTransformer = new Transformer<GraphMetadata, MyGraph>() { public MyGraph transform(GraphMetadata metadata) { assert (metadata.getEdgeDefault().equals(EdgeDefault.UNDIRECTED)); return newGraph; } }; // create the vertex transformer Transformer<NodeMetadata, Integer> vertexTransformer = new Transformer<NodeMetadata, Integer>() { public Integer transform(NodeMetadata metadata) { // create a new vertex Integer v = newGraph.getVertexCount(); // save layout information if (metadata.getProperty("x") != null && metadata.getProperty("y") != null) { double x = Double.parseDouble(metadata.getProperty("x")); double y = Double.parseDouble(metadata.getProperty("y")); posMap.put(v, new Point2D.Double(x, y)); } newGraph.addVertex(v); return v; } }; // create the edge transformer Transformer<EdgeMetadata, MyEdge> edgeTransformer = new Transformer<EdgeMetadata, MyEdge>() { public MyEdge transform(EdgeMetadata metadata) { MyEdge e = new MyEdge(newGraph.getEdgeCount()); if (metadata.getProperty("color") != null) e.color = Integer.parseInt(metadata.getProperty("color")); return e; } }; // create the useless hyperedge transformer Transformer<HyperEdgeMetadata, MyEdge> hyperEdgeTransformer = new Transformer<HyperEdgeMetadata, MyEdge>() { public MyEdge transform(HyperEdgeMetadata metadata) { return null; } }; // create the graphMLReader2 GraphMLReader2<MyGraph, Integer, MyEdge> graphReader = new GraphMLReader2<MyGraph, Integer, MyEdge>( fileReader, graphTransformer, vertexTransformer, edgeTransformer, hyperEdgeTransformer); // Get the new graph object from the GraphML file graphReader.readGraph(); }
From source file:FileChooserDemo2.java
public void actionPerformed(ActionEvent e) { // Set up the file chooser. if (fc == null) { fc = new JFileChooser(); // Add a custom file filter and disable the default // (Accept All) file filter. fc.addChoosableFileFilter(new ImageFilter()); fc.setAcceptAllFileFilterUsed(false); // Add custom icons for file types. fc.setFileView(new ImageFileView()); // Add the preview pane. fc.setAccessory(new ImagePreview(fc)); }// w ww.j a v a 2 s . c o m // Show it. int returnVal = fc.showDialog(FileChooserDemo2.this, "Attach"); // Process the results. if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.append("Attaching file: " + file.getName() + "." + newline); } else { log.append("Attachment cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); // Reset the file chooser for the next time it's shown. fc.setSelectedFile(null); }
From source file:DesktopAppTest.java
public DesktopAppFrame() { setLayout(new GridBagLayout()); final JFileChooser chooser = new JFileChooser(); JButton fileChooserButton = new JButton("..."); final JTextField fileField = new JTextField(20); fileField.setEditable(false);/*from www . ja va 2s .co m*/ JButton openButton = new JButton("Open"); JButton editButton = new JButton("Edit"); JButton printButton = new JButton("Print"); final JTextField browseField = new JTextField(); JButton browseButton = new JButton("Browse"); final JTextField toField = new JTextField(); final JTextField subjectField = new JTextField(); JButton mailButton = new JButton("Mail"); openButton.setEnabled(false); editButton.setEnabled(false); printButton.setEnabled(false); browseButton.setEnabled(false); mailButton.setEnabled(false); if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) openButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.EDIT)) editButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.PRINT)) printButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.BROWSE)) browseButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.MAIL)) mailButton.setEnabled(true); } fileChooserButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (chooser.showOpenDialog(DesktopAppFrame.this) == JFileChooser.APPROVE_OPTION) fileField.setText(chooser.getSelectedFile().getAbsolutePath()); } }); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().open(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); editButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().edit(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); printButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().print(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); browseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(new URI(browseField.getText())); } catch (URISyntaxException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }); mailButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { String subject = percentEncode(subjectField.getText()); URI uri = new URI("mailto:" + toField.getText() + "?subject=" + subject); System.out.println(uri); Desktop.getDesktop().mail(uri); } catch (URISyntaxException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }); JPanel buttonPanel = new JPanel(); ((FlowLayout) buttonPanel.getLayout()).setHgap(2); buttonPanel.add(openButton); buttonPanel.add(editButton); buttonPanel.add(printButton); add(fileChooserButton, new GBC(0, 0).setAnchor(GBC.EAST).setInsets(2)); add(fileField, new GBC(1, 0).setFill(GBC.HORIZONTAL)); add(buttonPanel, new GBC(2, 0).setAnchor(GBC.WEST).setInsets(0)); add(browseField, new GBC(1, 1).setFill(GBC.HORIZONTAL)); add(browseButton, new GBC(2, 1).setAnchor(GBC.WEST).setInsets(2)); add(new JLabel("To:"), new GBC(0, 2).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2)); add(toField, new GBC(1, 2).setFill(GBC.HORIZONTAL)); add(mailButton, new GBC(2, 2).setAnchor(GBC.WEST).setInsets(2)); add(new JLabel("Subject:"), new GBC(0, 3).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2)); add(subjectField, new GBC(1, 3).setFill(GBC.HORIZONTAL)); pack(); }
From source file:com.webcrawler.WebCrawlerMain.java
public void initInternalComponents() { progBarDownload.setStringPainted(true); fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setVisible(false);/*from ww w . j av a 2 s. co m*/ }
From source file:SwingWorkerTest.java
public SwingWorkerFrame() { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); textArea = new JTextArea(); add(new JScrollPane(textArea)); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); statusLine = new JLabel(" "); add(statusLine, BorderLayout.SOUTH); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/* w ww . ja va2s . c o m*/ JMenu menu = new JMenu("File"); menuBar.add(menu); openItem = new JMenuItem("Open"); menu.add(openItem); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // show file chooser dialog int result = chooser.showOpenDialog(null); // if file selected, set it as icon of the label if (result == JFileChooser.APPROVE_OPTION) { textArea.setText(""); openItem.setEnabled(false); textReader = new TextReader(chooser.getSelectedFile()); textReader.execute(); cancelItem.setEnabled(true); } } }); cancelItem = new JMenuItem("Cancel"); menu.add(cancelItem); cancelItem.setEnabled(false); cancelItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { textReader.cancel(true); } }); }