Results 1 to 3 of 3

Thread: JtextField

  1. #1
    kashifu is offline Member
    Join Date
    Jun 2008
    Rep Power

    Default JtextField


    i have a problem while dealing with JtextFields.

    actually i have created a browse button by using the JFileChooser.
    now when the user selects the file, and clicks open button in browse window,
    the text in the filed is supposed to get updated to the filename of selected file.
    But i cannot figure out how to do this.

    ActionListener aListener;
    aListener = new ActionListener(){
    public void actionPerformed(ActionEvent e){
    final JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(browse);
    File selectedFile = fc.getSelectedFile();
    filename = fc.getName(selectedFile);

    // filepath is the JTextField which shud get updated. and this does not do the trick

    Last edited by kashifu; 06-25-2008 at 07:16 PM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    If the user cancels or closes the dialog without selecting a file you may not be interested in the value returned by getSelectedFile.
    Java Code:
    int returnVal = fc.showOpenDialog(browse);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fc.getSelectedFile();

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    What do you see as the value of filename if you put a System.out.println("fn=" + filename);
    after the getName() ?

Similar Threads

  1. how to focus to another JTextfield?
    By birdofprey in forum AWT / Swing
    Replies: 2
    Last Post: 04-09-2008, 01:08 PM
  2. Using Columns With JTextField
    By The Evil Genius in forum AWT / Swing
    Replies: 1
    Last Post: 03-17-2008, 01:01 AM
  3. Clean the content of the JTextField
    By elizabeth in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2007, 08:38 PM
  4. help with JTextfield
    By gary in forum New To Java
    Replies: 4
    Last Post: 07-11-2007, 01:58 PM
  5. Replies: 1
    Last Post: 05-20-2007, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts