As we are using JDesktopPane with JInternalFrames for our software, I am wondering if we can have Shortcut Icons (to particular Frame) placed inside the desktop pane (Similar to Windows desktop shortcuts). I searched for this but no luck.
Any idea guys to make this happen??
The following is not a "good" solution, but maybe OK-ish for certain application cases. The main difficult is that the central class that comes into play here is
JInternalFrame.JDesktopIcon
, and the documentation of this class contains aWarning:
However, the corresponding functionality in
JInternalFrame
simply is not there. And although one has to accept that theJDesktopIcon
class might be removed in future versions, it seems very unlikely for me, considering the broad usage of this class in the internal Swing UI implementations.However: One option to achieve this is to create a custom extension of the
BasicDesktopIconUI
. Fortunately, this class handles most of the janitorial work, like dragging support and un-iconifying the frame on double clicks.As a result, one can easily sneak custom icons into such an implementation (I only used a placeholder here: A red cross on a black background. But it can be an arbitrary
Image
.)This is implemented here as a MCVE. The general UI handling may be different in an actual application, but the basic idea is to create the custom UI class and assign it to the internal frame icons.