Displaying the path of the file selected by a FileChooser in a TextField

I'm just getting started with Swing. I developed a simple dialog box that has two text fields and two buttons. The objective is to open two files using those two buttons. I used FileChooser to select the files. Now, I want to display the path of the selected files in their corresponding TextFields. I use the following code to do that.
final FileChooser fc1 = new FileChooser();
final FileChooser fc2 = new FileChooser();
final TextField tf1 = new TextField();
final TextField tf2 = new TextField();
private void button1ActionPerformed(ActionEvent evt)
            int returnVal1 = fc1.showOpenDialog(labelPhpFile);
            if (returnVal1 == JFileChooser.APPROVE_OPTION)
                File file1 = fc1.getSelectedFile();
                String fileName1 = file1.getName();               
                String filePath1 = file1.getPath();
                tf1.setText(filePath1);
private void button2ActionPerformed(ActionEvent evt)
            int returnVal2 = fc2.showOpenDialog(labelPhpFile);
            if (returnVal2 == JFileChooser.APPROVE_OPTION)
                File file2 = fc2.getSelectedFile();
                String fileName2 = file2.getName();               
                String filePath2 = file2.getPath();
                tf2.setText(filePath2);
}The above code works fine only for the first file. Mean the path of the file selected using fc1 is getting displayed in the tf1 TextField. But, the file selected using fc2 is not getting displayed tf2 TextField. Please help me.
Thank you :)

h1. The Ubiquitous Newbie Tips
* DON'T SHOUT!!!
* Homework dumps will be flamed mercilessly.
* Have a quick scan through the [Forum FAQ's|http://wikis.sun.com/display/SunForums/Forums.sun.com+FAQ].
h5. Ask a good question
* Don't forget to actually ask a question. No, The subject line doesn't count.
* Ask once
    - Don't Crosspost!
    - Two people answering one question independantly is a waste of there time.
* Don't even talk to me until you've:
    (a) [googled it|http://www.google.com.au/] and
    (b) looked it up in [Sun's Java Tutorials|http://java.sun.com/docs/books/tutorial/] and
    (c) read the relevant section of the [API Docs|http://java.sun.com/javase/6/docs/api/index-files/index-1.html] and maybe even
    (d) referred to the JLS (for "advanced" questions).
* [Good questions|http://www.catb.org/~esr/faqs/smart-questions.html#intro] get better Answers. It's a fact. Trust me on this one.
    - Lots of regulars on these forums simply don't read badly written questions. It's just too frustrating.
      - FFS spare us the SMS and L33t speak! Pull your pants up, and get a hair cut!
    - Often you discover your own mistake whilst forming a "Good question".
    - Many of the regulars on these forums will bend over backwards to help with a "Good question",
      especially to a nuggetty problem, because they're interested in the answer.
* Improve your chances of getting laid tonight by writing an SSCCE
    - For you normal people, That's a: Short Self-Contained Compilable Example.
    - Short is sweet: No-one wants to wade through 5000 lines to find your syntax errors!
    - Often you discover your own mistake whilst writing an SSCCE.
    - Solving your own problem yields a sense of accomplishment ;-)
h5. Formatting Matters
* Post your code between a pair of {code} tags
    - That is: {code} ... your code goes here ... {code}
    - This makes your code easier to read by preserving whitespace and highlighting java syntax.
    - Copy&paste your source code directly from your editor. The forum editor basically sucks.
    - The forums tabwidth is 8, as per [the java coding conventions|http://java.sun.com/docs/codeconv/].
      - Indents will go jagged if your tabwidth!=8 and you've mixed tabs and spaces.
      - Lines longer than 80 characters should be wrapped.
      - Proper indentation illustrates program logic.
* Post your error messages between a pair of {code} tags:
    - That is: {code} ... errors here ... {code}
    - To make it easier for us to find, Mark the erroneous line(s) in your source-code. For example:
        System.out.println("Your momma!); // <<<< ERROR 1
    - Note that error messages are rendered basically useless if the code has been
      modified AT ALL since the error message was produced.
    - Here's [How to read a stacktrace|http://www.0xcafefeed.com/2004/06/of-thread-dumps-and-stack-traces/].
* The forum editor has a "Preview" pane. Use it.
    - If you're new around here you'll probably find the "Rich Text" view is easier to use.
    - WARNING: Swapping from "Plain Text" view to "Rich Text" scrambles the markup!
    - To see how a posted "special effect" is done, click reply then click the quote button.
If you (the newbie) have covered these bases *you deserve, and can therefore expect, GOOD answers!*
h1. The pledge!
We the New To Java regulars do hereby pledge to refrain from flaming anybody, no matter how gumbyish the question, if the OP has demonstrably tried to cover these bases. The rest are fair game.

Similar Messages

  • How do i get the path of the file selected for opening in JFileChooser

    hi
    I need to get the path of the file selected for opening or saving in the JFileChooser dialog box.Is there any method available.if not how do i get that?
    Thanks and Regards
    Saminathan.

    don't know if its the best/only way, but you could use the getSelectedFile() method in JFileChooser which returns a file and then use the getAbsolutePath() file method

  • When attempting to open a hyperlink to a PDF file on the web from a Microsoft WORD for Mac 2011 (14.3.9) document, Safari 7.0 instead displays the file as text?

    When attempting to open a hyperlink to a PDF file on the web from a Microsoft WORD for Mac 2011 (14.3.9) document, Safari 7.0 instead displays the file as text?

    As seen in http://answers.microsoft.com/en-us/mac/forum/macoffice2011-macword/has-the-word- 2011-for-mac-invisible-toolbars/018a3ab6-0570-4ad5-abf8-5b6427fdde3e?msgId=e111b f0a-0e32-4fa3-9536-f349dad8439d
    and it worked for me:
    1. Quit Word
    2. In the Finder's menu bar, select Go > Go to folder and type or paste: ~/Library/Preferences/
    3. Click on Go
    4. Locate the preference file com.microsoft.Word.plist, then Option-drag it to the desktop to create a backup copy
    5. Go to Applications/Utilities and open Terminal
    6. Paste the following bold command at the $ prompt (it's a single line):
         defaults write com.microsoft.Word 14\\Toolbars\\Show_HIToolbar -boolean TRUE
    7. Press Return and then quit with Command Q
    8. Start Word and test. If the fix works, trash the backup file in the Desktop file. Otherwise, restore it.
    In the original source the author also mentions the change in Word 2008

  • Displaying the File Name in a Cell

    In version 2 of Numbers you used to be able to display the file name in a cell. If you copied a worksheet and gave it a new file name, that new name would automatically appear in the cell, so at a glance you could see which version of the worksheet you were looking at. As far as I can see that facility has gone in Version 3. Unless I have missed something?

    Hi Xabianblanca,
    Not *quite* as convenient but of course there is an easy partial workaround for this.
    Step 1. Click the triangle next to the document title:
    Step 2. Command-c. (the document name has already been selected for you).
    Step 3. Select the cell where you want to insert the document name and command-v.
    As for the Insert Date and Time menu pick there is a workaround that is just as easy to use as the original menu pick, after a quick one-time setup.
    See the other workarounds in that thread for some of the other features that weren't included in Numbers 3.0.
    SG

  • Is that possible to display the user selection data in the printable page?

    Hi All,
    I'm going to add a printablepage button on my page.
    Here comes a questions.
    Is that possible to display the user selection data in the printable page?
    For example,
    I have a table in the page,with 10 records.User select 5 of them.Can I display these 5 records in the printable page?
    Please help.

    Hi Yannick,
    Thanks a lot for the information. It worked.
    The portlet data can be accessible using bindings, but parameter name can be different.
    Meanwhile I have got one more scenario, where the Portlet and Task Flow placed in different pages of WCP Application. On change of data in the Portlet the application should navigate to another page where the Task Flow placed and displays selected data.
    Basically I can not use any button for navigation. The navigation should happen once I do some action in Portlet.
    Is this possible? If yes can you please let me know the steps?
    Thanks in advance!
    Somnath
    Edited by: Somnath Basak on Dec 20, 2011 9:41 AM

  • How can I get the Organizer in Elements 12to display the file name and date of the thumbnail images?

    The View menu option to display the File Name is grayed out and thus I cannot display the file name.

    Hi,
    You need to go to View menu and check Details as well.
    You may even have to make the thumbnails larger by using the zoom slider at the bottom
    Good luck
    Brian

  • Not to display the file name in the browser bar.

    Hello,
    Merry Christmas to all,
    Is it possible not to display the file name in the browser bar?
    Like say, when we write www.rediff.com, the index page name is not displayed.
    Likewise is it possible for any other page too.
    What I want is not to display any of the page name for the whole application.
    Whichever page is requested the page name should not appear in the address bar of the browser.
    How will I do that, what logics should I apply?
    Please suggest,
    Thanks,

    first, what does this have to do with Java?
    second, no; in order to display something, the browser needs to know where it is. and if it knows, then a user can find out too. maybe you can make it not show up in an address bar sometimes, but that really achieves nothing

  • How to display the file status in the status bar?

    Hi all,
    Can anyone tell me how to display the file status in the status bar?
    The file status can consists: the type of the file, the size of the file etc..
    thanx alot..

        class StatusBar extends JComponent {
              JLabel l = new JLabel("ready");
            public StatusBar() {
                  super();
                  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
                  add(l);
              public void setText( String prompt ) {
                   l.setText(prompt);
                   setVisible( true );
            public void paint(Graphics g) {
                  super.paint(g);
        }

  • To display the content selected in multiselect control in a report..

    Hi,
    I have one requirement to display the content selected in multiselect.I explained my requirement below.
    I have 5 multiselect boxes.they are locality,designation,connection1,connection2,connection3.
    The corresponding designations will be displayed for the locality and the corresponding connection1 will be displayed for the designation and the corresponding connection2 will be displayed for the connection1 and the corresponding connection3 will be displayed for the connection2.everything is displayed correctly in the multiselect.
    My requirement here is till connection1 i'll select mandatorily. and if i select connection1 and click GO button without selecting connection2 and connection3 then the connection1 only should be displayed in the report not the connection2 and connection3.likewise if i stop till connection2 and click go then connection2 only has to be displayed in the report not the connection1 and connection3..How can i do this?
    i tried using dropdown and presentation variables but not all the values are displayed in dropdown and there is a limit in dropdown.so i'm going for multiselect..
    Can anyone help me..

    HI,
    Sai Kumar Potluri
    I tried in IDES it working.
    Here is the code.
    REPORT  ZPRA_TC_D.
    TABLES : SCARR.
    CONTROLS TC TYPE TABLEVIEW USING SCREEN 1.
    DATA : SELLINE TYPE I,
           SELINDEX TYPE I.
    DATA : ACT LIKE SCARR-CARRID,
           ANT LIKE SCARR-CARRNAME.
    DATA : ITAB LIKE SCARR OCCURS 0 WITH HEADER LINE.
    CALL SCREEN 1.
    *&      Module  STATUS_0001  OUTPUT
    *       text
    MODULE STATUS_0001 OUTPUT.
      SET PF-STATUS 'ME'.
    *  SET TITLEBAR 'xxx'.
    SELECT * FROM SCARR INTO TABLE ITAB.
    ENDMODULE.                 " STATUS_0001  OUTPUT
    *&      Module  MOV  OUTPUT
    *       text
    MODULE MOV OUTPUT.
      MOVE-CORRESPONDING ITAB TO SCARR.
    ENDMODULE.                 " MOV  OUTPUT
    *&      Module  USER_COMMAND_0001  INPUT
    *       text
    MODULE USER_COMMAND_0001 INPUT.
    CASE SY-UCOMM.
    WHEN 'BACK' OR 'UP' OR 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'SEL'.
      GET CURSOR FIELD SCARR-CARRID LINE SELLINE.
      SELINDEX = TC-TOP_LINE + SELLINE - 1.
      READ TABLE ITAB INDEX SELINDEX.
      ACT = ITAB-CARRID.
      ANT = ITAB-CARRNAME.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0001  INPUT
    In Flow Logic.
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_0001.
    LOOP AT ITAB WITH CONTROL TC.
      MODULE MOV.
    ENDLOOP.
    PROCESS AFTER INPUT.
    LOOP AT ITAB.
    ENDLOOP.
    MODULE USER_COMMAND_0001.

  • Display the file extension?

    Is there a way to display the file extension? I want to tag some as PSD files and I want to delete all gif files. Currently I am opening each in Photoshop elements to get the extension, which is very cumbersome. I know I can see the extension in finder, but I cannot assign keywords in finder.
    Thanks
    bob

    New Smart Album
    Filename -> Contains -> psd
    Regards
    TD

  • Firefox hangs when a file is uploaded using the file selection mechanism.

    A "not responding" condition occurs after about the third selection in the file selection mechanism when I upload or download a file.
    This problem also occurs with Thunderbird when I try to save an attachment and I want to specify a location. I have not noticed this problem on any other application. Window Explorer functions correctly.
    By File selection meachism, I mean the window that appears with the HTML statement <INPUT type="file">.
    This happenen every time when I use this mechanism although not always at the third level, sometimes at the second level, sometimes deeper.

    It is possible that there is a problem with the files sessionstore.js and sessionstore.bak in the Firefox Profile Folder.
    Delete the sessionstore.js [2] file and possible sessionstore-##.js [3] files with a number and sessionstore.bak in the Firefox Profile Folder.
    * Help > Troubleshooting Information > Profile Directory: Open Containing Folder
    * http://kb.mozillazine.org/Profile_folder_-_Firefox
    Deleting sessionstore.js will cause App Tabs and Tab Groups and open and closed (undo) tabs to get lost, so you will have to create them again (make a note or bookmark them).
    See also:
    * [1] http://kb.mozillazine.org/Session_Restore
    * [2] http://kb.mozillazine.org/sessionstore.js
    * [3] http://kb.mozillazine.org/Multiple_profile_files_created

  • How to set the the file selection mode of JFileChooser

    hi,
    i want to set the file selection mode to directories only for JFileChooser class but when i run the code it does not select the folder adn opens the folder instead. i want the user to select a folder from the file system . any ideas?

    Sorry, I misunderstood you question. I thought that you already set it to choose Directories and wondered when you can't select them when you double-click.
    use JFileChooser.setFileSelectionMode(int). This should solve your problem.
    Here is an example:
            JFileChooser jf = new JFileChooser();
            jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jf.showDialog(this, "Select");
            System.out.println(jf.getSelectedFile());
    unformatted
    JFileChooser jf = new JFileChooser();
    jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    jf.showDialog(this, "Select");
    System.out.println(jf.getSelectedFile());

  • How will i display the multiple select ids in the dashboard ?

    I have a form where there is a multiple select. When the form is submit, the ids for the multiple select is stored in the database as concatenate. For example, multiple select : 3,9,5,1.
    The ids of the multiple select is found in a table TABLE1 and the insertion is done in another table TABLE2.
    Now I have to display them in a dashboard.
    My question is how will i display the multiple select ids in the dashboard ?
    I have to do an innerjoin with TABLE1 to retrieve the names of the multiple select ids. I don't know how to do it because the column name for multiple select in TABLE2 is of type text and the column id in TABLE1 is of type int.
    Please help me solve this problem.
    Thanks in advance

    One general advice is, never store comma-delimited lists in the database. In fact, the reason is to avoid problems like the one you now face.
    The major suggestion here is to re-design your database. Make sure each selected item (for example 3, 9, 5 or 1) is stored in its own row.
    To solve the problem as it now stands, you could do something like
    <cfquery>
    select myItems
    from table2
    where id in (select id from table 1 where ...etc.)
    </cfquery>
    Then use ColdFusion's list functions to do what your dashboard requires you to do.

  • FileSelectPopup function in LabWondows cvi to display the files as icons

    Does anyone know hoe to default the FileSelectPopup in LabWindows CVI to display the files as icons?
    Solved!
    Go to Solution.

    I took a look at this on XP and you're right, the View settings aren't retained. However this is actually an issue with the operating system and not CVI. If you attempt this in Notepad you'll see the same behavior. In Windows 7 (probably Vista too but I didn't test it) this has actually been fixed and the View settings are retained in the Windows File Open dialogs (which is what FileSelectPopup launches internally).
    Kevin B.
    National Instruments

  • Dreamweaver CS6 for Mac: Is there a way to display the file path in Design View?

    Under Windows, DW's Design View shows you the path to the current file, right next to the document tab. I noticed the Mac version omits this handy feature. For those of us who work with lots of similarly named files distinguished only by folders, being able to quickly see what folder we're in is crucial. (see image below -- that's where Windows shows you the path, but is blank in Mac)
    Is there something I'm missing, or some way to get that functioning? I know that I can see the path if I switch to Live View, but that is kludgy and breaks my workflow.

    I use CoderPlus workspace & tabbed panels.  For me, the file url is on the far right side. See screenshot. 
    If you click the "Page Icon" in upper right corner to tile, the URL shows on the left side.
    Nancy O.

Maybe you are looking for