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
71
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,927
  • 9
  • 37
  • 54
66
votes
3 answers

How do I set a suggested file name using JFileChooser.showSaveDialog(...)?

The JFileChooser seems to be missing a feature: a way to suggest the file name when saving a file (the thing that usually gets selected so that it would get replaced when the user starts typing). Is there a way around this?
yanchenko
  • 56,576
  • 33
  • 147
  • 165
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
39
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…
34
votes
4 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
  • 3,107
  • 7
  • 34
  • 37
27
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
26
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
  • 91,574
  • 70
  • 187
  • 238
22
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,405
  • 21
  • 68
  • 114
22
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
  • 28,427
  • 76
  • 200
  • 317
22
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,441
  • 5
  • 23
  • 30
22
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
21
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
  • 291
  • 1
  • 2
  • 9
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
  • 13,857
  • 12
  • 66
  • 113
20
votes
4 answers

How to use the default file chooser for the operating system?

I was just wondering: how does Gmail use the Windows/Mac file chooser to upload files? Is there any way to do this in Java? Personally, I don't like the way that the JFileChooser looks like, and I thought it would be better for my users to be able…
mattbdean
  • 2,532
  • 5
  • 26
  • 58
19
votes
9 answers

JFileChooser select directory but show files

I feel like there should be a simple way to do this but I can't figure it out. I have a JFileChooser that allows the user to select directories. I want to show all the files in the directories to give the user some context, but only directories…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
1
2 3
77 78