• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

USB Detection

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.








 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot mention the 2 boolean class variables are no longered used, so please ignore them in your analysis of this snippet. I am using NetBeans 7 with Java 7 update 1, which performs superbly.
 
Greenhorn
Posts: 20
Google Web Toolkit Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;

something like,


You can also use HashSet because system file drives are unique set of items.
reply
    Bookmark Topic Watch Topic
  • New Topic