Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

64
LINES

< > BotCompany Repo | #1006982 // GradientTranslucentWindowDemo [seems to work on Windows only]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (104L/2K/4K).

!7

import static java.awt.GraphicsDevice.WindowTranslucency.*;
 
sclass GradientTranslucentWindowDemo extends JFrame {
    public GradientTranslucentWindowDemo() {
        super("GradientTranslucentWindow");
 
        setBackground(new Color(0,0,0,0));
        setSize(new Dimension(300,200));
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        JPanel panel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                if (g instanceof Graphics2D) {
                    final int R = 240;
                    final int G = 240;
                    final int B = 240;
 
                    Paint p =
                        new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0),
                            0.0f, getHeight(), new Color(R, G, B, 255), true);
                    Graphics2D g2d = (Graphics2D)g;
                    g2d.setPaint(p);
                    g2d.fillRect(0, 0, getWidth(), getHeight());
                }
            }
        };
        setContentPane(panel);
        setLayout(new GridBagLayout());
        add(new JButton("I am a Button"));
    }
}

p {
  // Determine what the GraphicsDevice can support.
  GraphicsEnvironment ge = 
      GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice gd = ge.getDefaultScreenDevice();
  boolean isPerPixelTranslucencySupported = 
      gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);

  //If translucent windows aren't supported, exit.
  if (!isPerPixelTranslucencySupported) {
      System.out.println(
          "Per-pixel translucency is not supported");
          System.exit(0);
  }

  JFrame.setDefaultLookAndFeelDecorated(true);

  // Create the GUI on the event-dispatching thread
  SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
          GradientTranslucentWindowDemo gtw = new GradientTranslucentWindowDemo();

          // Display the window.
          gtw.setVisible(true);
      }
  });
}

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: 479 / 611
Version history: 2 change(s)
Referenced in: