I am writing a drop zone application where I will load the information of the file dropped in. The information will be extracted from the file and stored across the network so there will be a couple of seconds between each drop. What I want is to disable the drop zone and show a message "Sending..." during that period of time. So far what I managed to do is prevent the application from accepting new drop-ins but the mouse cursor icon doesn't reflect that and it basically hung my application interface because I was sitting on the AWT-thread during the upload and processing. I am using glass pane to show the message "Sending..." Any idea how I can improve this?
Hi ... regarding the cursor you can use COMPONENT.setCursor(DragSource.DefaultMoveNoDrop);
And regarding the threading of you background process ... you want to take a look at...SwingUtilities.invokeLater(<RUNNABLE INSTANCE>) which runs your logic in an anonymous inner class of type Runnable
EDIT : And regarding the stopping of any more files being dropped, you can just discard the files that are dropped until the process in background thread is finished. You can do this using a global variable. In the background thread (RUNNABLE INSTANCE), set cursor and set a global variable (like isWorkInProgress = true). At this point you can discard the files that are being dropped. After process is finished reset the global variable, cursor.
Tarun Bolla wrote:And regarding the threading of you background process ... you want to take a look at...SwingUtilities.invokeLater
Better still, use a SwingWorker. That's what the class is designed for.
There are no new questions, but there may be new answers.
T H Lim
posted 8 years ago
I solved my problem the work in progress flag. What I did was, I spawn a new Thread. Within this Thread, I made a remote request. Once it has completed, I updated the Swing components using SwingUtilities.invokeLater(...) within the same Thread. Finally, reset the work in progress flag to false. DropTargetAdapter's dragEnter(...) and drop(...) will check work in progress flag and reject any further drop-in outright until the 1st task is completed.
I tried using SwingWorker but it didn't seem to solve my problem. It seems to me, SwingWorker still works within the single AWT thread. This means that when a drop in event happened and the AWT thread is busy, the event will be queued. Once the AWT thread is freed, it will pick up whatever in the queue. It will add those files which i dragged into drop-in area during the "drop-in disabled" period. As compared to the earlier solution where the AWT thread is free-ed, accepted the drop-in event and rejected it.
I don't understand SwingWorker well and I could have probably made a mistake. Any advise would be a great help.
Thank you guys for chipping in.
T H Lim
posted 8 years ago
As far as the cursor concerned, I used the system cursor.