Wednesday, February 12, 2020

Make transparent JPanel using Java Swing in netbeans

Swing is the most usual GUI widget toolkit that uses in java. It's also easier to follow, even for a beginner.

When we are making an application we have to use JPanel to attach any other components to the window. To make this jpanel more styler we can make the jpanel transparent.  

There are several steps to follow to make transparent the JPanel in Netbeans.

  1. Drag and drop a JPanel into the JFrame Area.
  2. Use the following code to change the background details of the jpanel.
         jpanelname.setBackground(new Color(0,0,0,0));

             
                                                                            Image:-ITP Project  2019
  There are several numerical parts in the Color method. First 3 numerical parts for the color you chose. And the last part is the density of the transparency. the value should be between 0-250. the higher value you add, getting decrease transparency.

Example:-for Lower value

                                                                                      Image:-ITP Project  2019
                                                                          
            

                                                                                                      Image:-ITP Project  2019
                   

             for Higher value

                                  Image:-ITP Project  2019

                                                                    Image:-ITP Project  2019

The transparent effect only works when the file is running. You won't be able to see this effect in the design window.

No comments:

Post a Comment