aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes I have question about JFilechooser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "I have question about JFilechooser?" Watch "I have question about JFilechooser?" New topic
Author

I have question about JFilechooser?

Julian Trung
Greenhorn

Joined: Dec 30, 2008
Posts: 9
Hi every body,
Can I add "Open Button" in Save Dialog of JFileChooser like File Download's dialog?
How can I add a dialog same with File Download's dialog in Swing application?
Sorry for stupid question!!!


SCJP(83%)
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Hi Julian,
Welcome to the Ranch.

Why do you want to have an Open button in Save dialog? Any particular reason why you cannot use JFileChooser.showOpenDialog()?
What is this "File Download" dialog? Can you provide some more details?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Julian Trung
Greenhorn

Joined: Dec 30, 2008
Posts: 9
Sorry,
I mean now Save File Dialog has 2 button: Save and Cancel button, I want to add another button like "Open Button" so my dialog will has three buttons like attached image below


[Thumbnail for 2-23-2009 2-09-52 PM.png]

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

Sorry.
It is not possible to have Open and Save on the same dialog using the existing JFileChooser.
However, you can always create your own.
Easiest way (I think) would be to subclass JFileChooser.
Julian Trung
Greenhorn

Joined: Dec 30, 2008
Posts: 9
Thanks Maneesh Godbole,
So Do you know how can I use the dialog in attacted image in Swing app?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

As per your attachment, the user has already chosen a file.
What you can do is present the user with a file chooser.
If you use JFileChooser.showDialog() method, you can specify the button text. Just check out the API on how to use it.
When the user has selected a file, you can present him with another dialog with a choice of open./save/cancel. For this JOptionPane suggests itself.

If you are a newbie, I would recommend you read these
http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
Julian Trung
Greenhorn

Joined: Dec 30, 2008
Posts: 9
It's good idea for me, but I don't how to open directly excel file by Microsoft Excel App in my Swing App. Can you help me again?
Sorry I am a newbie so question also newbie
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

You want to open an excel file in your application (display contents of the excel file on your UI) or from your application?
If you want the latter, search the forums as this question comes up quite frequently. You will find a solution which is platform independent.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Julian Trung wrote:Sorry,
I mean now Save File Dialog has 2 button: Save and Cancel button, I want to add another button like "Open Button" so my dialog will has three buttons like attached image below

That's not a JFileChooser type dialog. It is a regular dialog with some labels, icons, buttons and a hyperlink. Only if you press Save will a file chooser be shown.

You could do the same yourself, by making a custom JDialog subclass. Save will call the JFileChooser, Cancel will close the dialog and Open will open the file. (That is a bit harder than the rest though). You'll have to play around a bit with the layout as well.

As for the hyperlink, if you really need one there are some examples on Java2S.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Julian Trung
Greenhorn

Joined: Dec 30, 2008
Posts: 9

Dear Rob Prime, these example don't support excel file, the hyperlink not working when i click them. But after all thanks you so much
 
 
subject: I have question about JFilechooser?