I have an undecorated JFrame
with some contents on it (Labels, Images, etc.). I need the JFrame
to pass all the events through it. For example: when a click is made on that JFrame
, I want it to pass that click through, to the window/anything that is underneath the frame.
Problem Example:
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame f = new JFrame("Test");
f.setAlwaysOnTop(true);
Component c = new JPanel() {
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g.create();
g2.setColor(Color.gray);
int w = getWidth();
int h = getHeight();
g2.fillRect(0, 0, w,h);
g2.setComposite(AlphaComposite.Clear);
g2.fillRect(w/4, h/4, w-2*(w/4), h-2*(h/4));
}
};
c.setPreferredSize(new Dimension(300, 300));
f.getContentPane().add(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
com.sun.awt.AWTUtilities.setWindowOpaque(f,false);
}
- In this case, the JFrame has a border with close/minimize/fullscreen controls, and graphics on the JFrame still catch the events while just the transparent parts pass them through. I need both (transparent parts, and with graphics) to pass through the events.
Video Example of my goal: https://www.youtube.com/watch?v=irUQGDDSk_g
Similar question:
- This question tries to achieve a similar goal, but the JFrame is decorated (has close/minimize controls with an outer frame), and graphics still catch the user control events.
Question: How can I make a JFrame with graphics, that will not catch the events from the user controlling, but to pass in through?