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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:24:17+00:00 2026-05-27T13:24:17+00:00

I have a JFileChooser and Im able to print the Absolute Path in console.

  • 0

I have a JFileChooser and Im able to print the Absolute Path in console.
I need to show the FilePath in a Text field as soon as the User selects the file.

Below is the code please let me know how to do it.

        public void actionPerformed(ActionEvent ae) {

        JFileChooser fileChooser = new JFileChooser();
        int showOpenDialog = fileChooser.showOpenDialog(frame);

        if (showOpenDialog != JFileChooser.APPROVE_OPTION) return;

Please let me know if you need any other details.

  • 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-27T13:24:18+00:00Added an answer on May 27, 2026 at 1:24 pm

    You need to listen to the changes that occur when using the JFileChooser, see this snipet of code:

    JFileChooser chooser = new JFileChooser();
    
    // Add listener on chooser to detect changes to selected file
    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY
                    .equals(evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser)evt.getSource();
                File oldFile = (File)evt.getOldValue();
                File newFile = (File)evt.getNewValue();
    
                // The selected file should always be the same as newFile
                File curFile = chooser.getSelectedFile();
            } else if (JFileChooser.SELECTED_FILES_CHANGED_PROPERTY.equals(
                    evt.getPropertyName())) {
                JFileChooser chooser = (JFileChooser)evt.getSource();
                File[] oldFiles = (File[])evt.getOldValue();
                File[] newFiles = (File[])evt.getNewValue();
    
                // Get list of selected files
                // The selected files should always be the same as newFiles
                File[] files = chooser.getSelectedFiles();
            }
        }
    }) ;
    

    All you need to do inside the first condition is set the value of your textfield to match the new selected filename. See this example:

    yourTextfield.setText(chooser.getSelectedFile().getName());
    

    Or just

    yourTextfield.setText(curFile.getName());
    

    It is the method getName() from class File that will give you what you need.
    Help your self from de API docs to see what each method does.

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

Sidebar

Related Questions

In my Java application I need to select a path using JFileChooser. The code
I have a small java GUI application with a text field on it. When
I have a JFileChooser that lets users choose an image for themselves. I want
I have a question about the JFileChooser in Swing. I'm trying to get multiple
How can I enforce the JFileChooser filetype (when saving). I have implemented a file
I'm constructing a JFileFilter on a JFileChooser, however an error occurs where I have
I have a dialog using JFileChooser. When I save a file by FileOutputStream ,
I have a JButton which launches a JFileChooser. However the JFileChooser often takes a
I have this problem: I am choosing a file from JFileChooser and if i
I have this program where u can download files and i want the JFileChooser

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.