Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:34:21+00:00 2026-06-09T03:34:21+00:00

Below is the code which i’m using to make the content pane transparent.What i

  • 0

Below is the code which i’m using to make the content pane transparent.What i don’t understand is if i comment out the line “setBackground(new Color(0,0,0,0)); ” my window is just painted with the gradient color and its opaque .However using the above line of code makes it transparent.

Can anyone tell what is the relation between this “setBackground(new Color(0,0,0,0)); ” and the gradient color which i’m setting for JPanel.
Thanx in advance.

import java.awt.Color;
import java.awt.FlowLayout;
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.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;


public class transparent extends JFrame {

public transparent() {
    super("Transparent Window");

    setBackground(new Color(0,0,0,0));//problem with this line

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(300,200);
    getContentPane().setLayout(new FlowLayout());

    JPanel jp=new JPanel(){
        public void paintComponent(Graphics g)
        {
            //super.paintComponent(g);
            Graphics2D g2=(Graphics2D)g;
            Paint gp=new GradientPaint(300, 700, new Color(20,20,210,0), 100, 00, new Color(10,20,40,255));
            g2.setPaint(gp);
            g2.fillRect(0, 0, getWidth(),getHeight());
        }
    };

    setContentPane(jp);
    JButton jbtn=new JButton("Enter");
    add(jbtn);
    setVisible(true);

}
public static void main(String[] args) {
    // TODO Auto-generated method stub

    JFrame.setDefaultLookAndFeelDecorated(true);

    SwingUtilities.invokeLater(new Runnable(){public void run(){new transparent();}});
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:34:22+00:00Added an answer on June 9, 2026 at 3:34 am

    The color (0,0,0,0) is fully transparent, as is any color with a alpha-component (fourth parameter in the Color-contructor) set to zero.

    http://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#Color(int, int, int, int)

    public Color(int r, int g, int b, int a)    
    

    Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 – 255).
    Parameters:
    r – the red component
    g – the green component
    b – the blue component
    a – the alpha component

    http://en.wikipedia.org/wiki/Alpha_compositing

    In computer graphics, alpha compositing is the process of combining an image with a background to create the appearance of partial or full transparency.

    When you set this as your background, the frame will become transparent! This is crucial, because if your frame is not transparent, having a transparent panel on top will only let you see through this panel and onto the underlying frame. Making the frame transparent as well let’s you see through to whatever lies behind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
Below is the code which I wrote to display a tooltip content. As the
I have the below code which prints out the date which is 10 working
I have the below code which prints out lines of text as long as
I am using JQuery. I have below JQuery Code which working fine in Firefox,
I am unable to find out the bug in the below code which i
I am using the below code which gives me the string of one element
I am using the below code which is working fine in chrome, IE but
i'm currently using the below code which extracts the InnerText, however, what happens is
I am using C#, Ajax for coding. Please see below code which I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.