8

I am trying to implement icon overlaying on files and folders just like Tortoise SVN or Dropbox does.

I did a lot of searching on the Internet, but I cannot find a solution in Java.

Can anyone help me with this? enter image description here

baharcglr
  • 111
  • 5
  • 1
    Good question, but I would think it is not possible to do such a thing as java programs run in the Java virtual machine, which decouples them from the operating system they run on. Not posting as an answer as I am not sure. – W. Goeman Mar 23 '12 at 16:10
  • You'll likly need to use JNI to jump into native code to actually make the change ( that is, if it is even possible via some WinAPI ). – Java42 Mar 23 '12 at 17:16
  • @W.Goeman yes, it seems diffucult or impossible in java, but I think that there should be an easy way to do it. I don't know but maybe there is a library for icon overlaying in java or etc. – baharcglr Mar 23 '12 at 17:28
  • 1) There's a hard limit of 15 icon overlays. No, not for your application, for the *all contributors in the OS*. That is, tortoise-*, TFS, whatever other shell extensions, they all share a pool of icon overlays. (So you've already got too many icons.) More information at http://blogs.msdn.com/b/youhana/archive/2012/01/09/why-am-i-not-seeing-the-icon-overlays-in-shell-extensions-tfs-power-tools.aspx 2) Yep, JNI is the way. Here's what you'll need to call in native land: http://www.codeproject.com/Articles/7484/How-to-overlay-an-icon-over-existing-shell-objects – Edward Thomson Mar 23 '12 at 17:32
  • @EdwardThomson I am planning to use 3 types of icons for overlay. It won't exceed the limit, right? I downloaded and looked the example in codeproject, but it is in C++. While searching, I found J7Goodies for icon overlaying on taskbar button. what about files - folders?http://www.strixcode.com/j7goodies/#overlay_icon – baharcglr Mar 23 '12 at 17:46
  • http://stackoverflow.com/questions/4589929/can-you-do-icon-overlays-using-java-on-windows-os – TheBlastOne Mar 26 '12 at 17:16

2 Answers2

4

I am sorry to confirm your fears, but it can't be done in Java.

Since the Windows Explorer is the one in control, Icon Overlay is sort of a plug-in. It has to be implemented as a DLL (not a JNI but a true native DLL), and registered in the Windows Registry. As you saw in CodeProject article, your DLL has to implement specific interface - IShellIconOverlayIdentifier.

Take for example the TortoiseSVN implementation.

TortoiseSVN's DLL is loaded by the Explorer and attached to its process:

DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */)
{
  ...
  if (dwReason == DLL_PROCESS_ATTACH)
  ...

In order to do this in Java you would need to write a DLL that would load the JVM and your JAR which would be an overkill.

As for the Tray Icon overlay, your Java application is the one in control so it can be done.

Cebence
  • 2,406
  • 2
  • 19
  • 20
1

I had the same problem and just found a solution for Java 1.7+ in combination with native and jni dlls. Works with Windows Vista+, Mac and Linux.

You can find the GIT project here: https://github.com/liferay/liferay-nativity

See my SO question here: Method to implement Windows Explorer icon overlays with Java

Community
  • 1
  • 1
metamagikum
  • 1,307
  • 15
  • 19