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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:04:29+00:00 2026-06-04T22:04:29+00:00

I have a slight problem with BufferedImage and JPanel. I am creating a game

  • 0

I have a slight problem with BufferedImage and JPanel. I am creating a game with some 2d animation.

Basically i have an animationHandler that will loop through the pictures and depending on the rotation will also display it correctly. But the problem is – when I load in the pictures my Jpanel wont draw anything. It doesnt event matter if I comment out the custom paint methods – the paintComponent method wont draw anything and it seems like it skips the paintCompontent method. Even though the game doesnt crash and the timer still is running – it wont use the paintComponent method in an extended JPanel.

The class that contains the timer – calls the JPanel throught JPanel.repaint();

Here is the loadImg method

/**
 * Test method to check animationHandler and bufferedImgs
 */
private void loadImages() {
    BufferedImage b_1;
    BufferedImage b_2;
    BufferedImage b_3;
    BufferedImage b_4;
    BufferedImage b_5;

    BufferedImage[] imgs = new BufferedImage[5];
    try {
        b_1 = ImageIO.read(new File("warlock1.png"));
        b_2 = ImageIO.read(new File("warlock2.png"));
        b_3 = ImageIO.read(new File("warlock3.png"));
        b_4 = ImageIO.read(new File("warlock4.png"));
        b_5 = ImageIO.read(new File("warlock5.png"));

        imgs[0] = b_1;
        imgs[1] = b_2;
        imgs[2] = b_3;
        imgs[3] = b_4;
        imgs[4] = b_5;

        animationHandler.addAnimation(imgs);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Cheers!

  • 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-04T22:04:30+00:00Added an answer on June 4, 2026 at 10:04 pm

    You’re could possibly be loading images on the Swing event thread or EDT (Event Dispatch Thread), and since the EDT is responsible for all Swing graphics and user interactions, this will freeze your Swing application until the loading is complete. The solution: load the images on a background thread such as can be obtained from a SwingWorker object. Please check out the Concurrency in Swing tutorial for more on this subject.

    Also, if possible, and if the images aren’t too large, it is usually best to load the images once and then hold a reference to them or to an ImageIcon.

    And finally, whatever you do, don’t load images inside of the paintComponent(...) method. This method must be lean and mean — as fast as possible, and it should concern itself only with painting and nothing else. Else your program’s responsiveness could become pitifully slow.

    Also, regarding:

    it wont use the paintComponent method in an extended JPanel.

    You might want to show us this code.

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

Sidebar

Related Questions

I have this GWT code below which have some slight problem: It's either the
I'm trying to get deeper into advanced-SQL'ing but have a slight problem with some
I have a slight problem with getting the options within the select tag. Some
I have a slight problem with creating a button on the server side code.
Hey all, have a slight problem here. In CakePHP I have a controller that
I am creating a coverflow plugin but I have a slight problem when it
I have a slight problem where when the user plays my game for more
Slight problem i have been pondering on, i have a class that loads a
people. I have slight problem with GD2 text on image. I have everything working
I have a slight problem with a path: D:\\Music\\DJ Ti%C3%ABsto\\Tiesto\\Adagio For Strings (Spirit of

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.