This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am running a background thread which, every 3 seconds, should detect whether a USB device has been inserted into the computer, and then changes the ViewPort view of the ScrollPane containg JTree to reflect the new drive. This end of it works perfectly, but the trouble is when a user removes the USB device and the program needs to detect this change.
Can you use HashMap<String,File> to maintain a list of drives available? Where String key is the drive letter and File is the corresponding drive. This will help cross checking with drives anytime later. In your thread, you can cross check the entire map you are maintaining whenever the drives count is lesser than previous attempt; basically you need to maintain drives count as well;
You can also use HashSet because system file drives are unique set of items.