• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I have question about JFilechooser?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic