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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:48:45+00:00 2026-05-30T04:48:45+00:00

I am setting a background image in JPanel with this JPanel panel = new

  • 0

I am setting a background image in JPanel with this

JPanel panel = new JPanel(){
            @Override
            public void paint(Graphics g) {
                super.paint(g);
                g.drawImage(ImageHelper.createResizedCopy(image, height, width, false), 0, 0, null);
            }

        };


        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.setPreferredSize(new Dimension(height, width));
        panel.setOpaque(false);
        panel.add(new JLabel("SCIENCE FAIR"));
        panel.setBorder(new RoundedBorder(1,2,new Color(100, 200, 112)));

        return panel;

I was expecting paintComponents method to respond but somehow paintComponents is not responding but paint is doing the job for painting a background image in JPanel.
This JPanel is the child of another JPanel .
The Parent JPanel is using MigLayout and inside the parent JPanel, I am adding 4 different JPanels with different different background image.

Background image is done but on top of Background image , I am not able to add JLabel, so I doubt the paint method is the issue

  • 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-30T04:48:47+00:00Added an answer on May 30, 2026 at 4:48 am

    You’re painting the entire component after the children are painted — you’re painting right over them, in other words. Never override paint() in a Swing component; override paintComponent() instead, and be sure to call super.paintComponent() after painting the background image.

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

Sidebar

Related Questions

Supposing I'm setting a background image for a web page in CSS like this:
<a class=success href=javascript:void(0)></a> //CSS for setting background for above link a.success:hover{ //set background image
I have tried setting the background image this way, but it doesn't work. Any
What's the difference between setting background image in layout xml and setting it from
I am having an issue with setting the background-image of a #x to the
I'm setting a view background to a repeating image using colorWithPatternImage. If the view
I'm working on setting background image sized 320X480 jpg, for >= android 2.2 versions.
I have this CSS background-image: linear-gradient(360deg,rgb(255,255,255) 25% ,rgb(241,123,25) 75%); with -moz, -o, -webkit, -ms
I am setting the background-image of some elements using css (some elements have no
I'm using setting the background image using methodology below. When I rotate my device

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.