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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:22:27+00:00 2026-05-19T15:22:27+00:00

I wanted to have a background image and two panels atop them. Learnt that

  • 0

I wanted to have a background image and two panels atop them. Learnt that JLayeredpane’s are quite suitable. So I extended a JLayeredPane in my class and tried to draw the image from paint(). I got it working. But when I added other layers over it they weren’t visible.

Again I thought of removing the bgimage from LayeredPane, added to the first layer above it(in JPanel). Now the image is not visible. Why does it happen? I wanted to do some thing like the screenshot I’ve provided. Pls help.

My code:

From my JFrame:

Container cp = this.getContentPane();
JLayeredPane backDropPanel = new JLayeredPane();    
cp.add(backDropPanel,BorderLayout.CENTER);
backDropPanel.add(new bgPanel(), new Integer(1),0);
backDropPanel.add(new itemScrollerPanel(), new Integer(1),0);

Panel’s:

class bgPanel extends JPanel{
String imageLocation = "/home/phantom/Desktop/BackDrop3.jpg";
private Image bgImage;
bgPanel(){
    bgImage = new ImageIcon(imageLocation).getImage();
    setPreferredSize(new Dimension(800,500));
    setLayout(null);
    setOpaque(true);
}

public void paint(Graphics g){      
super.paint(g);
g.drawImage(bgImage,0,0,this);
}}

class itemScrollerPanel extends JPanel{
    itemScrollerPanel(){
    setBounds(0,100,200,200);
    setBackground(Color.RED);
    setOpaque(true);

}}

In this code I get to see the itemsScrollerPanels’s RED BG drawn. But not the image of bgPanel class.

My requirement is something like this:

enter image description here

  • 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-19T15:22:28+00:00Added an answer on May 19, 2026 at 3:22 pm

    Without setting your bgPanel size explicitly, I get

    System.err.println(bgPanel.getSize());
    //java.awt.Dimension[width=0,height=0]
    

    If you change your code from

    setPreferredSize(new Dimension(800, 500));

    to

    setPreferredSize(new Dimension(800, 500));
    setSize(800,500);
    

    You should see the panel painted.

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

Sidebar

Related Questions

Let's say I wanted to have an application that could easily switch the DB
I have a block of code that works and I wanted to ask what
I wanted to easily blend a UIImage on top of another background image, so
Is it possible to have two background images? For instance, I'd like to have
I wanted to put a background image partially visible behind a list view. I
I wanted to group a number of toggle buttons and have them behave as
Say I wanted to have a project, and one-to-many with to-do items, and wanted
If I wanted to have Python distributed across multiple processors on multiple computers, what
Ruby is preinstalled on my Mac and so I wanted to have a look
I've been working on a project in Delphi 7 where I wanted to have

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.