01.
import
java.awt.*;
02.
import
javax.swing.*;
03.
import
static
java.awt.GraphicsDevice.WindowTranslucency.*;
04.
05.
public
class
TranslucentWindowDemo
extends
JFrame {
06.
public
TranslucentWindowDemo() {
07.
super
(
"TranslucentWindow"
);
08.
setLayout(
new
GridBagLayout());
09.
10.
setSize(
300
,
200
);
11.
setLocationRelativeTo(
null
);
12.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
13.
14.
15.
add(
new
JButton(
"I am a Button"
));
16.
}
17.
18.
public
static
void
main(String[] args) {
19.
20.
GraphicsEnvironment ge =
21.
GraphicsEnvironment.getLocalGraphicsEnvironment();
22.
GraphicsDevice gd = ge.getDefaultScreenDevice();
23.
24.
25.
if
(!gd.isWindowTranslucencySupported(TRANSLUCENT)) {
26.
System.err.println(
27.
"Translucency is not supported"
);
28.
System.exit(
0
);
29.
}
30.
31.
JFrame.setDefaultLookAndFeelDecorated(
true
);
32.
33.
34.
SwingUtilities.invokeLater(
new
Runnable() {
35.
@Override
36.
public
void
run() {
37.
TranslucentWindowDemo tw =
new
TranslucentWindowDemo();
38.
39.
40.
tw.setOpacity(
0
.55f);
41.
42.
43.
tw.setVisible(
true
);
44.
}
45.
});
46.
}
47.
}