Questions tagged [jfilechooser]

JFileChooser is a Java Swing component to provide a simple mechanism for the user to choose a file.

JFileChooser is a Java Swing component to provide a simple mechanism for the user to choose a file. For information about using JFileChooser, see How to Use File Choosers, a section in The Java Tutorial.

1167 questions
19
votes
5 answers

FileFilter for JFileChooser

I want to restrict a JFileChooser to select only mp3 files. But, the following code allows all file types: FileFilter filter = new FileNameExtensionFilter("MP3…
dev
  • 2,474
  • 7
  • 29
  • 47
18
votes
5 answers

Alternative to JFileChooser

I've a request to make some changes to a little applet that currently use a JFileChooser. One of the main complaints is that the file chooser is a pain in the ass to use because it behaves differently than the native widget, especially for…
gizmo
  • 11,819
  • 6
  • 44
  • 61
18
votes
2 answers

How can Swing dialogs even work?

If you open a dialog in Swing, for example a JFileChooser, it goes somewhat like this pseudocode: swing event thread { create dialog add listener to dialog close event { returnValue = somethingFromDialog } show dialog (wait until it is…
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
17
votes
5 answers

Set default saving extension with JFileChooser

I'm trying to save a file using JFileChooser. However, I seem to be having some trouble with it. Here's my code: if (e.getSource() == saveMenu) { JFileChooser chooser = new JFileChooser(); …
SaintLike
  • 9,119
  • 11
  • 39
  • 69
16
votes
2 answers

How can I start the JFileChooser in the Details view?

I would like my JFileChooser to start in details view, instead of the "List" view that it starts in. How do you do that?
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
15
votes
8 answers

adjust selected File to FileFilter in a JFileChooser

I'm writing a diagram editor in java. This app has the option to export to various standard image formats such as .jpg, .png etc. When the user clicks File->Export, you get a JFileChooser which has a number of FileFilters in it, for .jpg, .png…
amarillion
  • 24,487
  • 15
  • 68
  • 80
15
votes
6 answers

jfilechooser - set directory to a path in a file

I am trying to set the directory path in JFilechooser through something like this(using commons-io ) : String fileContents = IOUtils.toString(new FileInputStream("path.txt")); File theDirectory = new File(fileContents); filechooser = new…
fermk090
  • 151
  • 1
  • 1
  • 3
15
votes
4 answers

How to save file using JFileChooser?

I have a method in my application called "Save as" which Saves the image of my application on computer my into a file. I used the JFileChooser to let the users choose their desired location for saving the file. The problem is unless user explicitly…
Lokesh Kumar
  • 682
  • 2
  • 8
  • 27
14
votes
4 answers

How to restrict file choosers in java to specific files?

private void openMenuActionPerformed(java.awt.event.ActionEvent evt) { DBmanager db = new DBmanager(); if (!db.getCurrentUser().equals("Admin")) { JOptionPane.showMessageDialog(this, "You are Not Allowed to Run Applications"); …
Julius Gitonga
  • 311
  • 1
  • 2
  • 15
14
votes
6 answers

How to get full path directory from File Chooser

I am creating an application using Netbeans 7.1.2 and I am using a file chooser, but i do not want the file chooser to get a file, instead i want it to return the full path to the directory that it is currently at. When the user clicks open here, I…
newSpringer
  • 1,018
  • 10
  • 28
  • 44
13
votes
2 answers

How to open JFileChooser with predefined size

chooser = new JFileChooser(); chooser.setSize(300, 200); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { ....... } This doesn't work. Always opens in default size.
Stefanos Kargas
  • 10,547
  • 22
  • 76
  • 101
12
votes
2 answers

How to navigate to a network host in JFileChooser?

The Problem I have a JFileChooser and I need to programmatically set its currentDirectory to a network host containing several SMB shares (e.g. \\blah). Technically this is not a "directory" but rather a shell folder representing a list of available…
matvei
  • 746
  • 9
  • 22
12
votes
5 answers

Filter file types with JFileChooser

I am using JFileChooser to select a file and I am trying to limit the display to show only jpg or jpeg files. I have tried FileFilter and ChoosableFileFilter and it is not limiting the file selection. Here is my code: JFileChooser chooser = new…
Brian
  • 121
  • 1
  • 1
  • 3
11
votes
5 answers

File renameTo does not work

I am trying to add an extension to the name of file selected by a JFileChooser although I can't get it to work. This is the code : final JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); …
Giannis
  • 5,286
  • 15
  • 58
  • 113
10
votes
3 answers

JFileChooser getCurrentDirectory returning wrong current directory?

I am using JFileChooser in an app to browse for a directory however when I select the directory it returns the path to the folder above the folder I selected. i.e. I select "C:\Test" and it returns "C:\" Here is the Code I'm Using …
Talon06
  • 1,756
  • 3
  • 27
  • 51
1
2
3
77 78