Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[solved]how JTextField listen to JFileChooser  RSS feed

 
L Willie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


above code is my attemp,once i press button "Choose File",it would pop up JFileChooser and its related method.
after i choose a file and press "open" button on JFileChooser,the JTextField-jtf_file should listen and fill with selectedFile.getParent()+selectedFile.getName()

what type of listener should i use?

Sincerely

willie

[ October 20, 2008: Message edited by: L Willie ]
[ October 20, 2008: Message edited by: L Willie ]
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need a listener. If you press Open, the JFileChooser closes and the showOpenDialog method returns.

If this occurs, you are already printing the name etc of the selected file. You just need to add one line: setting the text of the text field.
 
L Willie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
You don't need a listener. If you press Open, the JFileChooser closes and the showOpenDialog method returns.

If this occurs, you are already printing the name etc of the selected file. You just need to add one line: setting the text of the text field.


jtf_file.setText(selectedFile.getParent()+"\\"+selectedFile.getName());

thank
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this?

jtf_file.setText(selectedFile.getAbsolutePath());
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!