Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-25-2008, 09:10 PM
Member
 
Join Date: Jun 2008
Posts: 1
kashifu is on a distinguished road
JtextField
hi

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.setText(filename);
// filepath is the JTextField which shud get updated. and this does not do the trick

}
};
thanks

Last edited by kashifu : 06-25-2008 at 09:16 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-26-2008, 02:05 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
If the user cancels or closes the dialog without selecting a file you may not be interested in the value returned by getSelectedFile.
Code:
int returnVal = fc.showOpenDialog(browse); if(returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); ...
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-27-2008, 06:25 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
What do you see as the value of filename if you put a System.out.println("fn=" + filename);
after the getName() ?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to focus to another JTextfield? birdofprey AWT / Swing 2 04-09-2008 03:08 PM
Using Columns With JTextField The Evil Genius AWT / Swing 1 03-17-2008 03:01 AM
Clean the content of the JTextField elizabeth AWT / Swing 1 07-26-2007 10:38 PM
help with JTextfield gary New To Java 4 07-11-2007 03:58 PM
How to determine if the value of a JTextField is double nemo New To Java 1 05-20-2007 01:19 PM


All times are GMT +3. The time now is 12:50 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org