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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:57:36+00:00 2026-06-12T14:57:36+00:00

Question: To hide a JPanel which has been added to a transparent JFrame when

  • 0

Question: To hide a JPanel which has been added to a transparent JFrame when the button is clicked.

Problem: The JPanel is not correctly hidden, but is still shown with darker colour. Without the alpha channel enabled, it hides ok.

Thanks for your help.

Example Code:

public class TestJFrame extends JFrame {

private JButton mSwitchButton = new JButton("Switch");
private JPanel mPanel = new JPanel();

public static void main(String[] args) {
    new TestJFrame();
}

public TestJFrame() {
    setSize(400, 300);      
    getContentPane().setLayout(new BorderLayout());
    this.setBackground(new Color(50, 50, 50, 50));      
    mPanel.setBackground(Color.RED);
    getContentPane().add(mPanel, BorderLayout.CENTER);
    getContentPane().add(mSwitchButton, BorderLayout.SOUTH);        
    mSwitchButton.addMouseListener( new MouseListener() {           
                    ...

        @Override
        public void mouseClicked(MouseEvent arg0) {
            mPanel.setVisible(false);
        }
                    ...
    });     
    pack();
    setVisible(true);
}
  • 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-12T14:57:37+00:00Added an answer on June 12, 2026 at 2:57 pm

    The darker color has to do with the JFrame — the JFrame itself is what is not being hidden correctly. Your JPanel is being hidden fine, however, when you set

    this.setBackground(new Color(50, 50, 50, 50));
    

    and then remove the JPanel, what you have left is that 50 alpha value. Setting it to:

    this.setBackground(new Color(50, 50, 50, 0));
    

    corrected this when I tested it on my machine.

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

Sidebar

Related Questions

This question has been thrown around without an answer. YES, we can hide the
My question is simple, How to hide back button in navigation bar? I see
My question is, why I can not use hide() & show() to hide/show table
Basic logic question about show() and hide() . When a li is clicked, I
got a question, is it possible to hide image and show iframe which are
I'm learning jQuery and have a question on how to hide the submit button
My question is, what is the best way to handle non-visible pages? $('.results').slice('//hidden pages').hide();
The question says it all. To clarify: I am not trying to hide the
$(#infoBox).hide(, function(){ alert('hidden!'); }); Just a small question, but my code breaks when I
This question I've already been answered for webforms app, but can I hide my

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.