File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Show FTP log in JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Show FTP log in JTextField" Watch "Show FTP log in JTextField" New topic

Show FTP log in JTextField

Ale Io

Joined: Jan 21, 2011
Posts: 1
Hi! I hope I'm in the right section of the forum, excuse me if I'm not.
In my java program I have to send a file to a ftp server. During the transfer I would like to show in a JTextField(called tLoading) the FTP log( for example: connecting to the server, transfer file, closing connection). I have a class with a JPanel and the JTextField inside the panel. From this class I call the static method upload of another class called FileUpload. This is the method:

The problem is that the JTextField tLoading donesn't change its value. I thought it was a thread problem, so I've created the following class:

and in the upload method I've replaced the tLoading.setText(...) instrucions with

The result is that the message msg is written in the right moment on the stdout but the JTextField value changes only at the end of the upload method. Any suggestions??
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 443

JTextField changes should be made on the EDT (Event dispatch thread), upload takes time so should not , assuming your load is not on the EDT your upload should spin off a job onto the EDT to update the text field.

"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3902

Welcome to CodeRanch, Ale Io

[How to ask questions] [Twitter]
I agree. Here's the link:
subject: Show FTP log in JTextField
jQuery in Action, 3rd edition