Creating a varying gradient translucent window : Swing « JDK 7 « Java

Creating a varying gradient translucent window

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsDevice.WindowTranslucency;
import java.awt.GraphicsEnvironment;
import java.awt.Paint;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Test {

  public static void main(String[] args) {
    GraphicsEnvironment envmt = GraphicsEnvironment
    GraphicsDevice device = envmt.getDefaultScreenDevice();

    if (!device
        .isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
          .println("Translucent windows are not supported on your system.");
    ApplicationWindow window = new ApplicationWindow();

class ApplicationWindow extends JFrame {

  public ApplicationWindow() {
    setBackground(new Color(0, 0, 0, 0));
    this.setSize(200, 200);
    JPanel panel = new JPanel() {
      protected void paintComponent(Graphics gradient) {
        if (gradient instanceof Graphics2D) {
          final int Red = 150;
          final int Green = 150;
          final int Blue = 150;
          Paint paint = new GradientPaint(0.0f, 0.0f, new Color(Red, Green,
              Blue, 0), getWidth(), getHeight(), new Color(Red, Green, Blue,
          Graphics2D gradient2d = (Graphics2D) gradient;
          gradient2d.fillRect(0, 0, getWidth(), getHeight());


Related examples in the same category

1.Handling multiple file selection in the FileDialog class
2.Managing the Opacity of a Window
3.Managing the Shape of a Window
4.Managing Window types
5.Mixing heavyweight and lightweight components
6.New border types in Java 7:RaisedSoftBevelBorder
7.New border types in Java 7:LineBorder width
8.New border types in Java 7:LoweredSoftBevelBorder
10.BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, Color.lightGray, Color.yellow)
11.Using the new JLayer Decorator for a password field
12.Managing extra mouse buttons and high resolution mouse wheels
13.Using the NumericShaper.Range enumeration to support the display of digits