Per – Pixel Translucency allows the programmer to control the translucency of a specific pixel over others. we will use this property to create a shaped window.
In this article we will try to implement shaped window in java by creating a transparent window and then painting the panel and then adding the Panel to the window.
- setBackground(Color c)method is used to set the background color to color c.
- color class is used to create a color of required transparency.
- setBackground(Color c) : method to set the background color to color c
- color(int r, int g, int b, int alpha) : creates a new color with specified red, green, blue and aplha value. where alpha is the value of translucency where 255 is opaque and 0 is transparent .
- getRGB(int x, int y) : returns the RGB value of the Coordinate x, y
- setColor(Color c) : set the color of graphics to c.
- Example 1
- Example 2
- Example 3 :
Output 3 :
Explanation : Here, in the input we can see that the background is made transparent whereas the
symbol of GeeksforGeeks remains as it was. Through the transparent background we can see the window below. We have separated the logo from its background and painted it on a transparent window .
The program below will illustrate how to create a shaped window using per – pixel translucency.
Input 1 :
Output 1 :
Input 2 :
Output 2 :
Input 3 :
Output 3 :
Note: I have chosen the color white as the background so I have separated it from the image and made it transparent. Its upon the discretion of the programmer to choose the background of the image .
Note : The above programs might not run in an online compiler please use an offline IDE.
It is recommended to use latest version of java to run the above programs, user might face problems if older versions of java are used.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Java Swing | Translucent and shaped Window in Java
- JSwing | Create a Magnifying tool using Java Robot
- How to Setup Sublime Text 3 for Java in Windows?
- 10 Ways to Create a Stream in Java
- Java | How to create your own Helper Class?
- How to create a Class in JShell of Java 9
- How to create Immutable class in Java?
- Different ways to create objects in Java
- How to create a REST API using Java Spring Boot
- How to create a TreeMap in reverse order in Java
- Factory method to create Immutable Set in Java 9
- Factory method to create immutable Map in Java 9
- Java Swing | Create a simple text editor
- Factory method to create Immutable List in Java SE 9
- ProcessBuilder in Java to create a basic online Judge
- How to create a Java HashMap of user defined class type?
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- How to create AnimatedGradient in Android?
- How to create a CalendarPickerView using TimeSquare library
- How to create a COVID-19 Tracker Android App
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.