Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following example creates a file chooser and displays it as first an open-file dialog and then as a save-file dialog:</p> <pre><code>String filename = File.separator+"tmp"; JFileChooser fc = new JFileChooser(new File(filename)); // Show open dialog; this method does not return until the dialog is closed fc.showOpenDialog(frame); File selFile = fc.getSelectedFile(); // Show save dialog; this method does not return until the dialog is closed fc.showSaveDialog(frame); selFile = fc.getSelectedFile(); </code></pre> <p>Here is a more elaborate example that creates two buttons that create and show file chooser dialogs.</p> <pre><code>// This action creates and shows a modal open-file dialog. public class OpenFileAction extends AbstractAction { JFrame frame; JFileChooser chooser; OpenFileAction(JFrame frame, JFileChooser chooser) { super("Open..."); this.chooser = chooser; this.frame = frame; } public void actionPerformed(ActionEvent evt) { // Show dialog; this method does not return until dialog is closed chooser.showOpenDialog(frame); // Get the selected file File file = chooser.getSelectedFile(); } }; // This action creates and shows a modal save-file dialog. public class SaveFileAction extends AbstractAction { JFileChooser chooser; JFrame frame; SaveFileAction(JFrame frame, JFileChooser chooser) { super("Save As..."); this.chooser = chooser; this.frame = frame; } public void actionPerformed(ActionEvent evt) { // Show dialog; this method does not return until dialog is closed chooser.showSaveDialog(frame); // Get the selected file File file = chooser.getSelectedFile(); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload