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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:36:33+00:00 2026-06-05T12:36:33+00:00

I have a jpanel and inner jpannels in it. When I set the panel

  • 0

I have a jpanel and inner jpannels in it.
When I set the panel background dynamically the inner colors dont change.
to init :

 myPanel.setOpaque(true)

and then

 myPanel.setBackground(...)

Is there a solution to set the background to all of the inner frames without looping or direct set?
Thank you.

  • 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-05T12:36:34+00:00Added an answer on June 5, 2026 at 12:36 pm

    No, but if you set the inner panels to non-opaque (transparent) you can change the outer panels directly:

    inner.setOpaque(false);
    

    You can always craete a class that you can use instead of JPanel:

    class TransparentJPanel extends JPanel {
        {
            setOpaque(false);
        }
    }
    

    Full example:

    static class TransparentJPanel extends JPanel {{
        setOpaque(false);
    }}
    
    public static void main(String... args) throws Exception {
    
        JFrame frame = new JFrame("Test");
    
        final JPanel panel;
    
        frame.add(panel = new JPanel() {{
            add(new TransparentJPanel());
            add(new TransparentJPanel());
            add(new TransparentJPanel());
        }}, BorderLayout.CENTER);
    
        frame.add(new JButton(new AbstractAction("Toggle") {
    
            @Override
            public void actionPerformed(ActionEvent e) {
                if (panel.getBackground().equals(Color.RED))
                    panel.setBackground(Color.GREEN);
                else
                    panel.setBackground(Color.RED);
            }
        }), BorderLayout.SOUTH);
    
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);
        frame.setVisible(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPanel for which I set some image as the background. I
I have a JPanel (A) which contains another JPanel (B). Each panel implements a
I have a JPanel that implements custom drawing to draw a background. Over this,
I have a JScrollpane that has a JPanel on the inside (and the panel
I have JPanel has already added to JFrame. And I have dynamically added JPanel.
I have a JPanel panel which contains a JTree tree . Sometimes the JTree
I have a JPanel that looks something like this: JPanel panel = new JPanel();
I have a problem making an inner class that extends from JPanel to draw
I have 3 JPanel, the first is the base panel and the other two
I have a JPanel and i am creating JButtons dynamically on runtime. I want

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.