Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 308223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:37:50+00:00 2026-05-12T07:37:50+00:00

I am trying to switch from using a JFileChooser to a FileDialog when my

  • 0

I am trying to switch from using a JFileChooser to a FileDialog when my app is being run on a mac so that it will use the OS X file chooser. So far I have the following code:

    FileDialog fd = new FileDialog(this);
    fd.setDirectory(_projectsBaseDir.getPath());
    fd.setLocation(50,50);
    fd.setFile(?);
    fd.setVisible(true);
    File selectedFile = new File(fd.getFile());

What would I put in for the question ? so that my file chooser would allow any directory to be the input for file chooser (the method that follows already checks to make sure that the directory is the right kind of directory I just want to the FileDialog to accept any directory).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:37:51+00:00Added an answer on May 12, 2026 at 7:37 am

    Assuming you’re determined to use the FileDialog instead of the portable JFileChooser, you need to set the system property so that FileDialogs created are for directories.

    The property in question is apple.awt.fileDialogForDirectories.

    So simply do the following:

    System.setProperty("apple.awt.fileDialogForDirectories", "true");
    FileDialog fd = new FileDialog(this); 
    fd.setDirectory(_projectsBaseDir.getPath()); 
    fd.setLocation(50,50);
    fd.setVisible(true); 
    File selectedFile = new File(fd.getFile());
    System.setProperty("apple.awt.fileDialogForDirectories", "false");
    

    It should be noted that this isn’t portable, however, since you’re looking to replace the portable JFileDialog, I assume that’s not an issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background Trying to switch from using Interceptor to Events. I have a ValidationInterceptor that
I've been trying to switch from using PerlSetEnv to using custom configuration directives .
Trying to convince someone to switch from .NET 1.1 I saw people saying that
I'm trying to write two batch files that will allow me to switch the
I am using VS2005 C#. I am trying to switch my login authentication from
I'm trying to use the Win32 API to make a sub-thread that reads from
Hey, I have been trying to switch my code from using an ie object
I'm trying to switch views in my app using this chunk of code: self->variable1
I am trying to switch from using Python 2.6.5 to using Python 3.2a2. I
I'm trying to convince a friend of mine to switch from OCaml to F#,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.