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.

1148 questions
68
votes
3 answers

JOptionPane YES/No Options Confirm Dialog Box Issue

I've created a JOptionPane and it only has two buttons YES_NO_OPTION . After JOptionPane.showConfirmDialog pops out , I want to click YES BUTTON to continue opening the JFileChooser and if I clicked NO BUTTON it should cancel the operation. It seems…
Sobiaholic
  • 2,737
  • 9
  • 32
  • 53
64
votes
3 answers

JFileChooser.showSaveDialog(...) - how to set suggested file name

The JFileChooser seems to be missing afeature: a way to suggest the file name when saving a file (the thing that usually gets selected so that it would get replaced when user starts typing). Is there a way around this?
yanchenko
  • 53,981
  • 33
  • 142
  • 163
52
votes
6 answers

How to "Open" and "Save" using java

I want to make an "Open" and "Save" dialog in java. An example of what I want is in the images below: Open: Save: How would I go about doing this?
Huuhaacece
  • 641
  • 1
  • 8
  • 10
38
votes
3 answers

how do I make jfilechooser only accept .txt

I trying to save my contact in my table but filechosser always setit to all file. is there way I can set it to accept .txt only and make it default or the only option. savecontact.addActionListener(new ActionListener() { public void…
31
votes
5 answers

Browse for folder dialog

I need to know how to get the "browse for folder" dialog in java. I am aware of SWT. But I need to do in swing? Is there any solution to this? [As we start on eclipse it will ask for choose workspace. We can see the browse for folder dialog at that…
Sri Sri
  • 2,917
  • 7
  • 29
  • 37
24
votes
4 answers

How do I restrict JFileChooser to a directory?

I want to limit my users to a directory and its sub directories but the "Parent Directory" button allows them to browse to an arbitrary directory. How should I go about doing that?
Allain Lalonde
  • 85,857
  • 67
  • 175
  • 234
23
votes
4 answers

Setting file creation timestamp in Java

I know setting the creation timestamp doesn't exist in Java because Linux doesn't have it, but is there a way to set a file's (Windows) creation timestamp in Java? I have a basic modification timestamp editor I made right here. import…
user263078
21
votes
3 answers

How to save file using JFileChooser in Java?

I have following code. It saves file but with empty content. What's wrong with it? public void saveMap() { String sb = "TEST CONTENT"; JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new…
Michał Tabor
  • 2,383
  • 5
  • 18
  • 30
20
votes
1 answer

JFileChooser - open in current directory

I have a simple JFileChooser set up in the following manner JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileFilter(new…
CodeGuy
  • 26,751
  • 71
  • 191
  • 310
20
votes
7 answers

JFileChooser change default directory in Windows

I want to change the default directory of my JFileChooser to "My Music" on Windows. This directory is C:\Users\Fre\Music on my account because my username is Fre The default is set on C:\Users\Fre\Documents (depends on OS i think). How can I change…
dumazy
  • 11,355
  • 12
  • 54
  • 100
19
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,597
  • 6
  • 42
  • 60
19
votes
3 answers

Bringing JFileChooser on top of all windows

I seem to have a problem with my very simple implementation of a file chooser dialogue that requires me to minimize Netbeans each time in order to get to it, and it gets pretty frustrating specially now with testing. I have seen a few solutions…
Carlos
  • 5,256
  • 19
  • 64
  • 113
19
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
  • 40,403
  • 57
  • 174
  • 291
19
votes
6 answers

JFileChooser filters

I am putting a JFileChooser in my program, but that only takes images. So I decided to add filters: Code import javax.swing.*; public class fileChooser { public static void main(String[] args) { JPanel panel = new JPanel(); final…
user1832583
19
votes
3 answers

JFileChooser to open multiple txt files

How can I use JFileChooser to open two text files and after I selected these files, I want to compare them, show on the screen etc. Is this possible?
zenx
  • 271
  • 1
  • 2
  • 9
1
2 3
76 77