JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TransparentPanel.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.tile;
2
3import java.awt.*;
4import javax.swing.*;
5import java.lang.reflect.Method;
6
7public class TransparentPanel extends JPanel {
8 public TransparentPanel() {
9 super.setOpaque(false);
10 setMixingCutoutShape(new Rectangle());
11 }
12
13 @Override
14 public void setOpaque(final boolean isOpaque) {
15 // Don't let this panel become opaque
16 }
17
18 /**
19 * Helper utility needed to implement TransparentPanel.
20 * This class provides the ability to cut out the background of a lightweight
21 * panel so that it can be layered on top of a heavyweight component and have
22 * the heavyweight component show through. For more infromation, see:
23 *
24 * http://today.java.net/article/2009/11/02/transparent-panel-mixing-heavyweight-and-lightweight-components
25 */
26 private static Method mSetComponentMixing;
27
28 /**
29 * Set the cut out shape on a given Component.
30 *
31 * @param c The Component on which to set the cut out shape.
32 * @param s The shape to cut out of the given Component.
33 */
34 public void setMixingCutoutShape(final Shape s)
35 {
36 // Get the cut out shape method
37 if (mSetComponentMixing == null) {
38 try {
39 final Class<?> awtUtilitiesClass =
40 Class.forName("com.sun.awt.AWTUtilities");
41 mSetComponentMixing =
42 awtUtilitiesClass.getMethod(
43 "setComponentMixingCutoutShape",
44 Component.class, Shape.class);
45 } catch (final Exception ex) {
46 ex.printStackTrace();
47 }
48 }
49
50 // Cut out the shape
51 if (mSetComponentMixing != null) {
52 try {
53 mSetComponentMixing.invoke( null, this, s );
54 } catch (final Exception ex) {
55 ex.printStackTrace();
56 }
57 }
58 }
59}
void setMixingCutoutShape(final Shape s)
Set the cut out shape on a given Component.