I want to create an overlay in Java that is transparent, always on top, and that I can click-through. I\'ve found some sim
I tried to make fully "event-transparent" (click-through as you call it) window, but there seems to be some native restrictions on that trick.
Check this window example:
public static void main ( String[] args )
{
Window w = new Window ( null );
w.add ( new JComponent ()
{
protected void paintComponent ( Graphics g )
{
g.setColor ( Color.BLACK );
g.fillRect ( 0, getHeight () / 2 - 10, getWidth (), 20 );
g.fillRect ( getWidth () / 2 - 10, 0, 20, getHeight () );
}
public Dimension getPreferredSize ()
{
return new Dimension ( 100, 100 );
}
public boolean contains ( int x, int y )
{
return false;
}
} );
AWTUtilities.setWindowOpaque ( w, false );
AWTUtilities.setWindowOpacity ( w, 0.5f );
w.pack ();
w.setLocationRelativeTo ( null );
w.setVisible ( true );
}
Window and component does NOT have any:
Also the component should ignore any kind of mouse events EVEN if there are any listeners due to the modified contains method.
As you can see - the area where nothing is painted on the component is event-transparent, but the filled area is not. Unluckly i didn't find any workaround to change that behavior. Seems that some "low-level" java methods are blocking the events.
And this is just a basic JComponent-based example. I don't even say about more complex Swing components like labels, buttons e.t.c. which might have their own event-listeners which could block events.