aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes help using JDIC to register file associations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "help using JDIC to register file associations" Watch "help using JDIC to register file associations" New topic
Author

help using JDIC to register file associations

Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I'm trying to find a way to use JDIC to associate a file type with a particular application, and it's not working for me. The ultimate goal is the I want a user to be able to be using, say, Windows Explorer, see a file, right click on it, and see an option pop up to invoke a particular program, passing the selected file as an argument. JDIC seems to support this, particularly according to this article. However in tests I've run so far, I haven't been able to observe it actually working. Here's some code I've tried:

The output I see (running on Windows 2000 Pro using JDIC 0.9.1) is:

Which is all well and good. The association did not exist initially (I chose .FOO as the filetype precisely because it is not associated with anything currently) and after calling registerAssociation, the association appears to exist - according to the Java program. Good.

Unfortunately, this appears to have no observable effect outside the JVM. Going to Explorer -> Tools -> Folder Options -> File types, I don't see an association listed for FOO files, or a description saying XXXXXX. If I right click or double click on a samlple file with a .FOO extension, I don't start up TextPad, nor see an option to open with TextPad. This appears to be true whether I let the Java program exist, or keep the main thread active with a prolonged sleep() call (shown commented out above). Closing Explorer and reopening it does not cause it to load new file associations, either.

So, does anyone have any ideas or suggestions on what I might be missing here? Thanks.
[ October 20, 2006: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You are missing the following code:



GenRocket - Experts at Building Test Data
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
D'oh! That was one of the first pieces I put in (back before I found the article I referenced). Somehow as I was shifting things around, trying different things, I dropped that piece without realizing. Now it's working - well not perfectly yet, but enough that I'm sure I can twiddle with it until it's right. Maybe by, oh, copying that sample code verbatim this time? Other than the error handling of course. Thanks, Gregg.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Jim Yingst:
D'oh! That was one of the first pieces I put in (back before I found the article I referenced). Somehow as I was shifting things around, trying different things, I dropped that piece without realizing. Now it's working - well not perfectly yet, but enough that I'm sure I can twiddle with it until it's right. Maybe by, oh, copying that sample code verbatim this time? Other than the error handling of course. Thanks, Gregg.


Hehe. No problem. The JDIC download has demo code with it. It's a swing app for doing the same thing. But that's where I noticed your missing piece.
Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
This is a random aside, Jim, but I thought i should mention it since you're using JDIC. If you want to use Balloons (those tool tips that pop up from a system tray icon) and you're on Windows 2000, you will not receive any events. For some reason it's an undocumented "feature" of win 2k that balloons don't send click events. (it's not just a JDIC issue)

I checked this against win2k service pack 2, 3 and 4. In the end, I had to write my own balloon tip class in order to react to a user clicking on the balloon.
 
Consider Paul's rocket mass heater.
 
subject: help using JDIC to register file associations