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 8368019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:17:33+00:00 2026-06-09T13:17:33+00:00

I current have a JFrame application that uses JTextField’s for input of file location

  • 0

I current have a JFrame application that uses JTextField’s for input of file location as per the code below.

    txtSource = new JTextField();
    txtSource.setToolTipText("/location/of/file/test.txt");
    txtSource.setText("/location/of/file/test.txt");
    txtSource.setBounds(16, 122, 412, 29);
    contentPane.add(txtSource);
    txtSource.setColumns(10);

What I would like to do is allow a directory search for the user to select the location of the file on the local computer and that location would populate into the Textbox.

I found the below information on JCHooser, but I’m not sure if this is way to go and would like assistance on how to implement.

String filename = File.separator+"tmp";
JFileChooser fc = new JFileChooser(new File(filename));

// Show open dialog; this method does not return until the dialog is closed
fc.showOpenDialog(frame);
File selFile = fc.getSelectedFile();

// Show save dialog; this method does not return until the dialog is closed
fc.showSaveDialog(frame);
selFile = fc.getSelectedFile();

Thanks in advance

  • 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-06-09T13:17:35+00:00Added an answer on June 9, 2026 at 1:17 pm

    Use

        int option = fc.showOpenDialog(frame);
        if (option == JFileChooser.APPROVE_OPTION) {
                txtSource.setText(fc.getSelectedFile().getAbsolutePath())
        }
    

    populates the text field with the selected file absolute file location

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

Sidebar

Related Questions

I current have some code that takes a screenshot and saves this to the
I current have this code that shows/hides content based on a select option. How
In my view file I current have the following code: @if ((Model.CustomerOrderTrackings != null)
My current problem is that I have a JFrame with a 2x2 GridLayout. And
I have a closeWindow() method which uses dispose() for the current JFrame to close
The code i current have is this. function update (){ latest_id = $('#image:first').data('position'); /*
Current Process: I have a tar.gz file. (Actually, I have about 2000 of them,
I have my current location fixed via CoreLocation. Now I want to get those
I current have the following regular expression to accept any numeric value that is
I current have the following XML fragment that I'm parsing to read its values

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.