Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

File Chooser Dialog Boxes

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to do is have a JFileChooser Save Dialog box to select the destination and file name of the file I will save. I have never worked with these before, but I am trying to figure them out.

Right now, I have it so I can open up the dialog box and choose where I want to save it and what to call it, this works fine, but what I want to do is have it so that the existing file name and directory and file name (the one I want to have set by default) is where the dialog box opens up to. for example:
if the file name is bob.txt in the C:\ directory, wheN I push the button to open the dialog box, the box pops up and is in the C:\ directory, it has "bob" in the file name box, and has the ".txt" selected in the file type combo box. how would I do this?

I know this may seem rather simple for some of you, but I dont know of any resources to help me figure this out (I dont have a Java book that covers this, and java.sun.com explanations only leave me confused.
if you could help me, or better yet give a link to a good tutorial (not java.sun.com) so that I could solve my own problems in the future, that would be great, thanks.
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
before opening the dialog, try this code, should be working.

fileChooser.setSelectedFile(youFile);
[ August 31, 2004: Message edited by: Pat Hays ]
 
Jeffrey Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK that works, I was sure exactly what the file in parenthsis was supose to be, but I figured it out.




New Question:
after the user selectes the file name they want and file type (.txt for example), and click on the save button, how can I get the extention that they selected from the file type combo box, right now when I go and get the file name and directory, I dont have the extention .txt in it unless the user included it there themsleves.

and also, if the filename already has a txt extention on it, how can I make the txt extention file type select itself from the file type list, and not go by default to the top one on the list.
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic