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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:36:05+00:00 2026-06-09T11:36:05+00:00

I have been learning Java for a few weeks now and I am really

  • 0

I have been learning Java for a few weeks now and I am really stuck when it comes to applying a background image to a JFrame. Every tutorial I’ve come across doesn’t create Frames the way I do ( I extend JFrame ) or if they do, the instructions aren’t clear enough for me to understand.

The code below is from a project of my own so help me practice what I’ve learned so far. Please could you build on the code below and explain to me what to add and where, so I may have an image as the background to my frame?

One thing I would really appreciate is if you could explain how things work and why there are needed and what they are actually doing – I don’t like the idea of blindly copying and pasting what you’ve done without any clue of how it works. The more depth in explanation, the better; even if it sounds patronising.

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

class MiniPad extends JFrame implements ActionListener {

    JPanel pan = new JPanel();
    ClassLoader ldr = this.getClass().getClassLoader();
    ImageIcon closeImg = new ImageIcon(ldr.getResource("\\images\\buttons\\closeBtn.png"));
    JTextArea note = new JTextArea("", 6, 21);
    JScrollPane notes = new JScrollPane(note);
    JButton close = new JButton(closeImg);

    public static void main(String[] args) {
        MiniPad padgui = new MiniPad();
    } //Instance of GUI

    public MiniPad() {
        super("Notepad");
        setSize(265, 191);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        add(pan);
        setVisible(true);
//Specifications
        note.setLineWrap(true);
        note.setWrapStyleWord(true);
        notes.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        close.setBorderPainted(false);
        close.setContentAreaFilled(false);
        close.setOpaque(false);
//Adding to JPanel 'pan'
        pan.add(notes);
        pan.add(close);
        close.addActionListener(this);
    }

    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == close) {
            setVisible(false);
        }
    }
}
  • 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-09T11:36:06+00:00Added an answer on June 9, 2026 at 11:36 am

    As to your question as it’s titled

    You will want to setup a custom Component (such as a JPanel) and override the paintComponent method

    Take a look at

    • Performing Custom Painting in Swing
    • Java 2D Graphics

    Now, you’re going to have some issues, the note pane will block most of the background, obscuring the image. This shouldn’t discourage from trying though 😉

    You’ll want to familiarise yourself with how Swing components can be made transparent as well.

    Some feedback 😉

    I don’t think you need to keep a reference to the Classloader, for what you’re using it for, it’s just adding weight and complexity to your code. It’s not a massive issue, but my first question was, “What’s he using the class loader for??”

    I’d probably adopt some kind of naming convention as well. Generally been a little more verbose will make it easier to understand the code.

    close ?? Is that an action? Maybe something like “closeButton”, at least I know it’s some type of button

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

Sidebar

Related Questions

I have been learning Hibernate for the past few weeks, I have gotten most
I have been learning GWT and Hibernate together for the last few weeks and
We have started learning Java in school, and we have been given a few
I've been learning Android for about two weeks now (expert in as2/3). I have
I am learning Java and have been given these options: How can you implement
I am currently learning about basic networking in java. I have been playing around
I have been learning Scala for the past couple of months and now I
I have been learning python for some time now. While starting this learning python
I'm 14 and have been learning java for about 4/5 months. I'm coding a
Hi I have been learning Java Swing for creating a chess game to practice

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.