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 3665928
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:49:11+00:00 2026-05-19T01:49:11+00:00

I have a dark-gray JPanel with a JLabel on it. I set new Color(0,

  • 0

I have a dark-gray JPanel with a JLabel on it. I set new Color(0, 0, 0, .5f) (tranparent) as the background of the JLabel and I change the text several times using a button. The problem is, everytime the text is changed, the previous text still remains behind the new text. I change the text from “123456789” to “1234567”, “12345” and “123”. Here is the screenshot:

alt text

How do I get rid of this “shadow”?

  • 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-05-19T01:49:11+00:00Added an answer on May 19, 2026 at 1:49 am

    I have a dark-gray JPanel with a JLabel on it. I set new Color(0, 0, 0, .5f) (tranparent)

    Swing does not support transparent backgrounds.

    Swing expects a component to be either:

    1. opaque – which implies the component will repaint the entire background with an opaque color first before doing custom painting, or
    2. fully transparent – in which case Swing will first paint the background of the first opaque parent component before doing custom painting.

    The setOpaque(...) method is used to control the opaque property of a component.

    In either case this makes sure any painting artifacts are removed and custom painting can be done properly.

    If you want to use tranparency, then you need to do custom painting yourself to make sure the background is cleared.

    The custom painting for the panel would be:

    JPanel panel = new JPanel()
    {
        protected void paintComponent(Graphics g)
        {
            g.setColor( getBackground() );
            g.fillRect(0, 0, getWidth(), getHeight());
            super.paintComponent(g);
        }
    };
    panel.setOpaque(false); // background of parent will be painted first
    

    Similar code would be required for every component that uses transparency.

    Or, you can check out Background With Transparency for custom class that can be used on any component that will do the above work for you.

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

Sidebar

Related Questions

I have a JScrollPane that holds a JLabel using the following code: //Create TEXT
I have used UITableView with default UITableViewCell. Here i have given dark gray color
I have a menu div which has a dark background. Inside it, I have
I like a dark background when coding and have customised it to a scheme
I Have two files. One extends JFrame, and another Extends JPanel. Whenever I change
I have a spinner which is in the Emulator light gray with black text
I have done some applet program in java, which will change the color of
In my application I have different Themes - one dark and one bright theme.
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have asked a very similar question, but I ended up using images instead

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.