To select a file path?

Hi all!
Currently I want to allow user to select the file path using those file dialog like JFileChooser/FileDialog... So that there's an input field that accepts a file name... Then another text field which will display the path that the user chose... I need to do that separately to write a .wav file... How do I do it?
I tried using JFileChooser and set this... (.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);) It only shows the directories, yes... But if I open a directory... without anymore directories in it... When I click on the "OK" button... It does not allow me to go on...
Cozel

How about this???
import java.io.*;
public class MyFileChooser extends javax.swing.JDialog {
         private javax.swing.JPanel cntrPnl;
         private javax.swing.JFileChooser chsr;
         private javax.swing.JButton cancelButton;
         private javax.swing.JButton svButton;
         private javax.swing.JTextField dirField;
         private java.io.File selFile = null;
    public MyFileChooser(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    private void initComponents() {
        chsr = new javax.swing.JFileChooser();
        cntrPnl = new javax.swing.JPanel();
        dirField = new javax.swing.JTextField();
        svButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
        chsr.setControlButtonsAreShown(false);
        chsr.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
        chsr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chsrActionPerformed(evt);
        chsr.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                chsrPropertyChange(evt);
        getContentPane().add(chsr, java.awt.BorderLayout.CENTER);
        dirField.setEditable(false);
        dirField.setMargin(new java.awt.Insets(0, 5, 0, 5));
        dirField.setPreferredSize(new java.awt.Dimension(200, 30));
        cntrPnl.add(dirField);
        svButton.setText("SAVE");
        svButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                svButtonActionPerformed(evt);
        cntrPnl.add(svButton);
        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
        cntrPnl.add(cancelButton);
        getContentPane().add(cntrPnl, java.awt.BorderLayout.SOUTH);
        pack();
    private void chsrPropertyChange(java.beans.PropertyChangeEvent evt) {
        dirField.setText(chsr.getCurrentDirectory().getAbsolutePath());
    private void svButtonActionPerformed(java.awt.event.ActionEvent evt) {
        selFile=chsr.getSelectedFile();
        this.hide();
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
        selFile = null;
        this.hide();
    private void chsrActionPerformed(java.awt.event.ActionEvent evt) {
        dirField.setText(chsr.getCurrentDirectory().getAbsolutePath());
    private void closeDialog(java.awt.event.WindowEvent evt) {
        setVisible(false);
        dispose();
    public static void main(String args[]) {
        MyFileChooser fc = new MyFileChooser(null, true);
        fc.show();
        File f = fc.getSelFile();
        if(f!=null)
            System.out.println("Selected File is: "+f);
        fc.dispose();
        System.exit(0);
    public File getSelFile() {
        return selFile;
}walker

Similar Messages

  • FM to select the file path for download into application server

    Hello,
    I need a FM to select the file path for download into application server. It is a F4 help .
    Its functionality should be simmilar to the one used for presentation server i.e. as fol
    CALL METHOD cl_gui_frontend_services=>file_save_dialog

    Hello,
    What about F4_DXFILENAME_TOPRECURSION? You can check other FMs of the group DX_FILE.
    BR,
    Suhas
    PS: I think these FMs are not released by SAP, so need to be cautious while using these

  • User Select File Path Before Running Rest of VI?

    I am designing a system where data is being acquired and written to 12 data files, and I would like to have the operator have the option of selecting the data path while keeping the filenames of the individual files constant. It is necessary for the data not to be acquired until the operator completes the prompt so the data acquisition and writing are synchronized.  How can design my VI to not start the data acquisition and writing the data until the operator has selected the file path?
    I've attached my program below. It has a producer/consumer design with two consumer loops. One consumer loop will process and write the data and the other controls a water bath based on the data that is acquired.
    Attachments:
    Composting System Program.vi ‏123 KB

    NT_Engineer,
    Hello! If I understand what you are asking correctly, you just want to have the user select a file path before you start your data acquisition, control, and file writing. Is this correct?
    There are multiple ways in which you could do this.
    As mentioned previously you could design your VI to operate like a State Machine.
    A flat sequence structure could be used to first execute a dialog portion of your code, and then the data acquisition portion.
    You could use an event structure to not start your program until a user clicked  "Done" button.
    Let me know if this is what you were asking.
    Ben Sisney
    FlexRIO V&V Engineer
    National Instruments

  • How to give dynamic file path in the selection  screen

    Hi All,
    How to give dynamic file path f4 functionality to user on the selection so that he can browse for the path in the presentation serve? I believe there is one fun module is there for this purpose I am not getting that
    Please help me in this regard.
    Thanks&Regards
    Mahesh

    HI,
    check this program.
    <b>report ZWA_TEST2.
    PARAMETERS: a(100) default 'PRESS F4'.
    data: filet type table of FILE_TABLE.
    data: wa type file_table.
    data: count type i.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR a.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
      CHANGING
        FILE_TABLE              = filet
        RC                      = count .
    loop at filet into wa.
      a = wa-FILENAME.
    endloop.</b>
    Regards,
    HRA

  • F4 help for file path in selection screen.

    Hi there,
    I defined one parameter p_path for file path using RLGRAP-FILENAME. I have not got F4 for this. How to solve this problem, can anybody pls help.
    Regards,
    Naseer.

    Hi,
    refer to the following code:
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pc.
    DATA: it_tab TYPE filetable,
              wf_subrc TYPE i.
    DATA: wf_pcfile LIKE rlgrap-filename.
      DATA: wf_filter TYPE string,
            wf_dir TYPE string,
            wf_title TYPE string,
            wf_ext TYPE string.
    *  if p_ml = 'X'.                  "Manula Load - PC File
      wf_title = text-012.          "Window title
      wf_ext  = '.TXT'.           "Extension of the file
      wf_filter = 'Text Files (*.TXT)|*.TXT'.         "File Type
      wf_dir = wf_pcfile.           "Directory
    *Adds a GUI-Supported Feature
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title      = wf_title
          default_extension = wf_ext
          file_filter       = wf_filter
          initial_directory = wf_dir
        CHANGING
          file_table        = it_tab
          rc                = wf_subrc.
    Hope this helps.
    <REMOVED BY MODERATOR>
    Regards,
    Sipra
    Edited by: Alvaro Tejada Galindo on Jan 31, 2008 9:48 AM

  • Physical file path on the selection screen from AL11 Tcode

    Hi All,
    Please let me know some body how do we give only physical file path(only directory not the file names) on the selection screen?I need to see when I press F4 only the physical file directories of the application server.
    Thanks in advance.
    Mahesh

    Hi,
    This FM will be helpful.....
    F4_dxfilename_toprecursion
    CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
    * EXPORTING
    *   I_LOCATION_FLAG       = ' '
    *   I_SERVER              = '?'
    *   I_PATH                =
    *   FILEMASK              = '*.*'
    *   FILEOPERATION         = 'R'
    * IMPORTING
    *   O_LOCATION_FLAG       =
    *   O_SERVER              =
    *   O_PATH                =
    *   ABEND_FLAG            =
    * EXCEPTIONS
    *   RFC_ERROR             = 1
    *   ERROR_WITH_GUI        = 2
    *   OTHERS                = 3
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Regards,
    Mdi.Deeba Najam.

  • Browse the File path selection in the selection screen

    I want to give the user the option to browse his/her desktop and selct a file path and windows name by clicking on a drop down.
    How do I do that?
    Thank you in advance

    hi ,
    there are so many function modules which will provide F4 Help for the path.
    Suppose you have given a parameter name path.
    You have to use these FMs in the event
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR path.
    Example :
    data : C_FNH_MASK TYPE DXFIELDS-FILEMASK VALUE '.',
    SEARCH_DIR TYPE DXFIELDS-LONGPATH VALUE '/SAPGLOBAL/USERS',
          FILE_PATH LIKE DXFIELDS-LONGPATH.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR path.
    CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
        EXPORTING
          I_LOCATION_FLAG = 'P'
          I_SERVER        = ' '
          I_PATH          = SEARCH_DIR
          FILEMASK        = C_FNH_MASK
          FILEOPERATION   = 'R'
        IMPORTING
          O_PATH          = PATH
        EXCEPTIONS
          RFC_ERROR       = 1
          OTHERS          = 2.
      CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
        EXPORTING
          I_LOCATION_FLAG = 'A'
          I_SERVER        = ' '
          I_PATH          = SEARCH_DIR
          FILEMASK        = C_FNH_MASK
          FILEOPERATION   = 'R'
        IMPORTING
          O_PATH          = FILE_PATH
        EXCEPTIONS
          RFC_ERROR       = 1
          OTHERS          = 2.
    If you remove 'P' and put 'A', then it is used for application server F4 help.
    you have F4_FILENAMEand F4_FILENAME_SERVER  for presentation and application servers respectively
    Reward points if helpful.
    Thanks and Regards.

  • Is it possible for a saved path to open a folder where the user can select the file to open?

    I would like to retieve a link via database that would open a folder of drawings, word documents, pdf files, excel files etc., where the user can select which file they want. Selected files would open in which ever format they were with programs that are already installed on the users computer. For example, the link would open a folder where several solid works files were, and a couple of Word documents. The user would select one of the Solid Works files, and it would open up in the Solid Works installation on the users computer. Is this possible, or must a link point directly to a file?

    I'm not sure I understand what you mean by "link". Are you referring to a URL that uses a "file://" protocol?
    The standard File Dialog VI has a "start path" input that you can set so the file dialog opens to that folder.

  • Selecting Multiple File Types With Path Control

    My application uses a file path control for the user to specify an output file.  This output file can have two different formats (.csv or .mbf) which is unknown until the user specifies it through the file dialogue.  However, when the user inputs a file name with a .mbf extension (test.mbf, for example), the file path control automatically appends the typed-in name with a .csv extension (test.mbf.csv).  Given that the Pattern field on the control is written like this: *.csv; *.mbf., it seems that the control is simply taking the first file pattern listed and appending it to whatever is typed into the File Name field in the file dialogue box.  Selection Mode is set to "Files" and "New or existing".
    Anyone know a way to smarten up the file control to recognize the appropriate file type?
    Using LabVIEW 8.6.1.
    Thanks!
    Andrew
    Solved!
    Go to Solution.

    Instead of using the file path control, try using the Fial Dialog Express VI. This will bring up the same dialog box but will allow you much more flexibility. Replace your file path control with a button ("Specify Path" in my example code):

  • File path select pop ups. Multiple searches found

    I just had a new HD installed, and I now have mountain lion. When I open Logic pro on an existing song, I now get a "File Path Select" box, which says that there are "multiple matches found in file." Is this because my audio interface, Inspire 1394 is no longer compatible with mountain lion? What can I do to remove this?

    Do you have many files with the same name in different songs, like "Bass" or "Guitar" etc? Perhaps with the new drive, the original file paths connecting your files to your songs no longer exists, so logic is searching and finding multiple files matching the file name that the song is looking for. Do you see the filepath belonging to the song in the select box? If so, select it.

  • How to get the file path of selected file using JFileChooser

    Hi All,
    I am trying to store the file on my FTP server after selecting the file from the user workstation using JFileChooser. But I am not able to write the file on FTP server or on user local machine where application is running. I am new to this FTP server coding. Can anyone help me in this.
    This is the code I wrote on button click user will able to select the file:
    String filename1;
    File file;
    JFileChooser fc = new JFileChooser();
    fc.showOpenDialog(this);
    file = fc.getSelectedFile();
    filename1 = file.getPath();
    txtFilePath.setText(filename1);
    Below is the code to write the file on my local machine first:
    BufferedWriter outFile = new BufferedWriter( fileName ) );
    outFile.write();
    outFile.flush( );
    outFile.close( );
    Any help will be greatly appriciated

    rp0428 wrote:
    >
    BufferedWriter outFile = new BufferedWriter( fileName ) );
    >
    There is NOTHING named 'fileName' in any of the code you posted so that code can't possibly compile let alone actually run.
    How can anyone help you if you won't post the actual code you are using?Its just a random snippet of other code that is totally irrelevant to this thread if you ask me.

  • LSMW :Is it possible to create F4 Help for File path selection

    Hi All .,
    Please let me know is it possible to create F4 help for file path creation in LSMW .
    thanks
    Sreenivas

    Hi,
    I don't get it.
    In the step " Specify files" you will have the option to pick your flat file which is on the desktop by pressing F4 .
    What is that you exactly want??
    Warm regards,
    Hari Kiran

  • Application server file path vaidation

    I have written the code for application server file path validation.
      DATA : l_fname TYPE filename-fileintern." type c.
      DATA : l_filpath TYPE filename-fileintern,
             l_filname(40) TYPE c.
    PARAMETER : p_sucfil LIKE rfpdo-rfbifile OBLIGATORY. " rlgrap-filename
    AT SELECTION-SCREEN ON p_sucfil.
    l_fname = p_sucfil.
    CALL FUNCTION 'FILE_GET_NAME'
      EXPORTING
      CLIENT                        = SY-MANDT
        logical_filename              = l_fname
       OPERATING_SYSTEM              = SY-OPSYS
      PARAMETER_1                   = ' '
      PARAMETER_2                   = ' '
      PARAMETER_3                   = ' '
      USE_PRESENTATION_SERVER       = ' '
       WITH_FILE_EXTENSION           = 'X'
      USE_BUFFER                    = ' '
      ELEMINATE_BLANKS              = 'X'
    IMPORTING
      EMERGENCY_FLAG                =
      FILE_FORMAT                   =
       FILE_NAME                     = l_filpath
    EXCEPTIONS
       FILE_NOT_FOUND                = 1
       OTHERS                        = 2
    IF sy-subrc <> 0.
      message 'Invalid file name' type 'E'.
    ENDIF.
    But always i will get Invalid file name.
    Y is it so.
    pls help me.

    Praveen,
    I have checked ur code and I found that if i give a logical file name from
    tran. FILE under folder 'Logical file name definition, cross client' then ur code works. Pl. check.
    Regards,
    Joy.
    DATA : l_fname TYPE filename-fileintern." type c.
    DATA : l_filpath TYPE filename-fileintern,
    l_filname(40) TYPE c.
    PARAMETER : p_sucfil LIKE rfpdo-rfbifile OBLIGATORY. " rlgrap-filename
    AT SELECTION-SCREEN ON p_sucfil.
      l_fname = p_sucfil.
      CALL FUNCTION 'FILE_GET_NAME'
      EXPORTING
      logical_filename = l_fname
    operating_system = sy-opsys
      with_file_extension = 'X'
      IMPORTING
      file_name = l_filpath
      EXCEPTIONS
      file_not_found = 1
      OTHERS = 2
      IF sy-subrc <> 0.
        MESSAGE 'Invalid file name' TYPE 'E'.
      ENDIF.

  • 'F4_FILENAME'. USER FILE PATH

    when I used the following function module  for user defined file path selection
    parameters: p_file like rlgrap-filename.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    PROGRAM_NAME = SYST-CPROG
    DYNPRO_NUMBER = SYST-DYNNR
    FIELD_NAME = ' '
    IMPORTING
    FILE_NAME = P_FILE.
    I am getting the follwing Dump error.
    Exception condition "NO_FIELDCATALOG_AVAILABLE" raised.
    Could any one help me correcting problem ?

    Try  this.
    report zrich_0001.
    data: ifiletable type filetable.
    data: xfiletable like line of ifiletable.
    data: rc type i.
    parameters: p_file1 type localfile default'C:test.txt'.
    at selection-screen on value-request for p_file1.
    call method cl_gui_frontend_services=>file_open_dialog
       EXPORTING
    *    WINDOW_TITLE            =
    *    DEFAULT_EXTENSION       =
    *    DEFAULT_FILENAME        =
    *    FILE_FILTER             =
         INITIAL_DIRECTORY       = 'C:'
    *    MULTISELECTION          =
      changing
        file_table              = ifiletable
        rc                      = rc
    *    USER_ACTION             =
      EXCEPTIONS
        FILE_OPEN_DIALOG_FAILED = 1
        CNTL_ERROR              = 2
        ERROR_NO_GUI            = 3
        others                  = 4.
    read table ifiletable into xfiletable index 1.
    if sy-subrc = 0.
      p_file1 = xfiletable-FILENAME.
    endif.
    Regards,
    RIch Heilman

  • Inserting file path/filename

    Hi, all out there,
    I've just strated using Pages '08, and exploring it. But Pages Help and User Guide do not tell me how to insert the file path or filename in the footer, so that it's automatically updated whenever changed. It's not in the Insert menu, and cannot find it in Insert > Function.

    Hi Peggy,
    Though that feature is useful isn't found in 10.4.10. The Devon Technologies WordService ReadMe file has the following:
    Insert:
    Contents Of Path
    Inserts files and folders of the selected path (tilde is expanded)
    and of all its subdirectories (e.g. select the path '~/' and this function
    will insert all contents of your home directory)
    Short Date Cmd-'{'
    Inserts the current date (no text selection necessary)
    Long Date Cmd-'}'
    Inserts the current date (no text selection necessary)
    Short Date & Time Cmd-'_'
    Insert the current date & time (no text selection necessary) Long Date & Time Cmd-'%'
    Insert the current date & time (no text selection necessary) Time
    Insert the current time (no text selection necessary)
    Maybe that's what you're seeing in your services menu perhaps.
    Sincerely,
    RicD

Maybe you are looking for