Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I have question about JFilechooser?

 
Julian Trung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Julian Trung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
2-23-2009 2-09-52 PM.png
[Thumbnail for 2-23-2009 2-09-52 PM.png]
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maneesh Godbole,
So Do you know how can I use the dialog in attacted image in Swing app?
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Julian Trung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic