Libraryless. Click here for Pure Java version (104L/2K/4K).
1 | !7 |
2 | |
3 | import static java.awt.GraphicsDevice.WindowTranslucency.*; |
4 | |
5 | sclass GradientTranslucentWindowDemo extends JFrame { |
6 | public GradientTranslucentWindowDemo() { |
7 | super("GradientTranslucentWindow"); |
8 | |
9 | setBackground(new Color(0,0,0,0)); |
10 | setSize(new Dimension(300,200)); |
11 | setLocationRelativeTo(null); |
12 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
13 | |
14 | JPanel panel = new JPanel() { |
15 | @Override |
16 | protected void paintComponent(Graphics g) { |
17 | if (g instanceof Graphics2D) { |
18 | final int R = 240; |
19 | final int G = 240; |
20 | final int B = 240; |
21 | |
22 | Paint p = |
23 | new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0), |
24 | 0.0f, getHeight(), new Color(R, G, B, 255), true); |
25 | Graphics2D g2d = (Graphics2D)g; |
26 | g2d.setPaint(p); |
27 | g2d.fillRect(0, 0, getWidth(), getHeight()); |
28 | } |
29 | } |
30 | }; |
31 | setContentPane(panel); |
32 | setLayout(new GridBagLayout()); |
33 | add(new JButton("I am a Button")); |
34 | } |
35 | } |
36 | |
37 | p { |
38 | // Determine what the GraphicsDevice can support. |
39 | GraphicsEnvironment ge = |
40 | GraphicsEnvironment.getLocalGraphicsEnvironment(); |
41 | GraphicsDevice gd = ge.getDefaultScreenDevice(); |
42 | boolean isPerPixelTranslucencySupported = |
43 | gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT); |
44 | |
45 | //If translucent windows aren't supported, exit. |
46 | if (!isPerPixelTranslucencySupported) { |
47 | System.out.println( |
48 | "Per-pixel translucency is not supported"); |
49 | System.exit(0); |
50 | } |
51 | |
52 | JFrame.setDefaultLookAndFeelDecorated(true); |
53 | |
54 | // Create the GUI on the event-dispatching thread |
55 | SwingUtilities.invokeLater(new Runnable() { |
56 | @Override |
57 | public void run() { |
58 | GradientTranslucentWindowDemo gtw = new GradientTranslucentWindowDemo(); |
59 | |
60 | // Display the window. |
61 | gtw.setVisible(true); |
62 | } |
63 | }); |
64 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv
No comments. add comment
Snippet ID: | #1006982 |
Snippet name: | GradientTranslucentWindowDemo [seems to work on Windows only] |
Eternal ID of this version: | #1006982/3 |
Text MD5: | 6bdec4be1f64bb2054b51122140abd2e |
Transpilation MD5: | 6c501ca094ad6802112b6ebd6707aa9b |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-02-21 20:35:18 |
Source code size: | 2097 bytes / 64 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 480 / 614 |
Version history: | 2 change(s) |
Referenced in: | [show references] |