Answer the question
In order to leave comments, you need to log in
Semi-transparent java window that ignores mouse clicks?
The task was to create an application, one of the components of which will be a translucent window that is always in the foreground, while behaving as if it does not exist. That is, if there is an application behind this horse, then only this application will respond to mouse clicks. Is it possible to do this with java? It's just a question of ignoring clicks.
Answer the question
In order to leave comments, you need to log in
1. I had an idea that a similar option might work:
public class NonResponsiveWindow extends JFrame
{
public NonResponsiveWindow ()
{
super ();
setLayout ( new BorderLayout () );
add ( new JPanel()
{
{
setOpaque ( false );
}
public boolean contains ( int x, int y )
{
return false;
}
public boolean contains ( Point p )
{
return false;
}
protected void paintComponent ( Graphics g )
{
super.paintComponent ( g );
Graphics2D g2d = ( Graphics2D ) g;
g2d.setRenderingHint ( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_OVER, 0.5f ) );
g2d.setPaint ( Color.GRAY );
Area area = new Area ( new Ellipse2D.Double ( 0, 0, getWidth (), getHeight () ) );
area.subtract ( new Area (
new Ellipse2D.Double ( 25, 25, getWidth () - 50, getHeight () - 50 ) ) );
g2d.fill ( area );
}
public Dimension getPreferredSize ()
{
return new Dimension ( 300, 300 );
}
} );
setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
setAlwaysOnTop ( true );
setUndecorated ( true );
AWTUtilities.setWindowOpaque ( this, false );
pack ();
}
public boolean contains ( int x, int y )
{
return false;
}
public boolean contains ( Point p )
{
return false;
}
public static void main ( String[] args )
{
new NonResponsiveWindow ().setVisible ( true );
}
}
And if, for example, after receiving the signal, play it but for a different window?This should be quite feasible using standard tools (you just need to correctly transfer the coordinates to the underlying window).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question