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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:31:51+00:00 2026-05-17T23:31:51+00:00

i found this link.. LINK what i want is there’s a JPanel that has

  • 0

i found this link.. LINK what i want is there’s a JPanel that has a background and another JPanel with half the size of the first JPanel but with an image that is transparent and with a face or a ball at the middle.. 🙂 just like the screenshot from the link.. is that possible to code in java? 🙂 im just thinking it like for web programming. just a sort of DIV’s to have that but i dont know in java.. 🙂 sorry for bad english.. 😀 i have this as a background..

package waterKing;

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;

 @SuppressWarnings("serial")

 public class Main extends JFrame {
MainData data = new MainData();

public static void main(String[] args) {
    Main frmMain = new Main();
    frmMain.setExtendedState(Frame.MAXIMIZED_BOTH);
    frmMain.setVisible(true);

}

public Main() {
    data.tk = getToolkit();
    data.d = data.tk.getScreenSize();

    data.jP = new JPanel() {            
        protected void paintComponent(Graphics g) {
            data.e = getSize();
            data.iI = new ImageIcon("images/mainBG.png").getImage();
            g.drawImage(data.iI,0, 0, data.d.width, data.d.height, null);
            super.paintComponent(g);    
        }                   
    };

    data.jP.setOpaque(false);
    data.jSp = new JScrollPane(data.jP);
    data.jB = new JButton("EXIT");
    data.jB.setBounds(10,10,200,40);
    data.jB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    data.jP.setLayout(null);
    data.jP.add(data.jB);       

    this.setTitle("Water King Inventory System");
    this.setUndecorated(true);
    this.getContentPane();
    this.add(data.jSp);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLocationRelativeTo(null);

}

 }

i dont know how to add another JPanel to show in the middle with this background alt text

  • 1 1 Answer
  • 1 View
  • 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-17T23:31:51+00:00Added an answer on May 17, 2026 at 11:31 pm

    i dont know how to add another JPanel to show in the middle with this background

    Its just like adding components to a panel. You need to use a layout manager and then the component will be positioned properly based on the rules of the layout manager. In your case you can set the layout manager of the background panel to be a BorderLayout. Then you can add a JLabel with the appropriate Icon to the center of the BorderLayout.

    You will need to set the preferred size (or override the getPreferredSize() method of your panel since you add it to a scroll pane. Scrollbars will only appear when the preferred size of the panel is greater than the size of the scroll pane.

    You should not be reading the image in your paintComponent() method since this method is called multiple times.

    You should not be using the “screen size” to determine the width/height of the image because the frame will contain a border. You need to use the size of the panel.

    Get rid of all the setBounds() code. Learn to use layout managers.

    For a general purpose background panel that takes into account most of the suggestions made here check out Background Panel.

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

Sidebar

Related Questions

I found this link http://artis.imag.fr/~Xavier.Decoret/resources/glsl-mode/ , but there isn't a lot of description around
I have found some info on the subject ( like this link) , but
Found this question that explained a way to communicate between layers. However there is
I want to fetch a list of all Salesforce objects. I found this link
I found this open-source library that I want to use in my Java application.
I found this link WPF_Example , but it is written in WPF. I am
Update : I just found this documentation page . Wish there was a link
I found this link on how to embed custom fonts in XAML apps. Is
i have a problem using the Catch Clipboard Events code found on this link
I've found a code which opens this link after logging in to google account

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.