Reputation: 55
I am coding a windows program in Java (something likes sticker on screen for writing some important notes, etc). Automatically, it saves and encodes everything you type in when it's closed. For save I made custom file extension (.T22) but it shows as blank page. I want to change that automatically when program is first started. Basically I want custom icon for save files likes for example photoshop has for its .psd files, but all made in java.
I tried looking through a lot of sites but I couldn't find anyone even talking about it.
Upvotes: 3
Views: 456
Reputation: 6808
This cannot be achieved from Java. Well, at least without administrator rights. Windows show icons for file extensions by taking values from Windows Registries. The thing is that, when an icon takes place, it must take for all users according to this link. In the link, HKEY_CLASSES_ROOT
is referred in order to achieve that. That's where the "administrator rights" part come. It's worth to mention, without being 100% sure, that a .JAR file (a java application) can be executed with admin rights, only if you execute cmd
as administrator and then java -jar myapp.jar
. I had spend a lot of hours one day in order to edit these registries from Java and i did not manage to do it without administrator rights. (If you do it, let me know how you did :) )
Now, assume you have admin rights, one way, would be a simple
reg
command from admin privileged cmd
.
As described in the previous link though, you cannot simple (i am not so sure) change the icon for a file extension, without giving the full path of your program's executable (.exe
). Yes, you guessed it right, your program, is not a windows executable. It is just a compressed file. So, this gets rejected as well.
Now, your problem heads right to How can I convert a JAR file to an EXE file?. Then, plus the admin rights, you might be able to do it.
My personal advice though, is to find a JAR to EXE converter which gives this option during program installation. I mean, i am sure you have seen in a windows installation something like "Associate .txt files with Notepad ++".
Upvotes: 1