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

  • Home
  • SEARCH
  • 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 426947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:31:48+00:00 2026-05-12T19:31:48+00:00

How can I draw a portion of my Java2D simulation that doesn’t change to

  • 0

How can I draw a portion of my Java2D simulation that doesn’t change to an image/buffer so I don’t have to redraw it’s primitives each time?

I have a portion of my Java2D simulation that requires me to draw thousands of small lines. However, this portion of the app doesn’t change once drawn so it doesn’t make sense to re-draw thousands of primitives each loop iteration (doing active rendering).

So, what object do I use to draw to and preserve it, and then allow me to simply draw this whole image to my canvas, and then draw on top of it what changes?

  • 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-12T19:31:49+00:00Added an answer on May 12, 2026 at 7:31 pm

    One could draw out to a BufferedImage, then later, draw the contents of the BufferedImage to a Swing component, like a JPanel.

    In order to draw to a BufferedImage, one would use the createGraphics to obtain the Graphics2D context of the image:

    BufferedImage img = new BufferedImage(width, height, type);
    Graphics2D g = img.createGraphics();
    // do drawing using the Graphics2D object.
    g.dispose();
    

    Then later, draw the contents of the BufferedImage to a JPanel by overriding the paintComponent method:

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(img, 0, 0, null);  // Draw img onto the JPanel.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my program that can draw rectangles. I have two problems I can't
i can draw a string/image... with drawInRect/drawAtPoint. but how about if i want to
Any idea how I can draw Bullet Points using Flex? instead of using image
How I can draw bezier curve in canvas. I have only start point and
I need a UIImageView that can draw itself in color or b/w according to
I have an Image. On the bottom portion of the image, I would like
I have a drawing application in Android that allows the user to draw with
I had a calculator app that can draw a function. I'm stuck in an
hey guys, I have a large image, and then i'm extracting a portion of
I have a graph where user can draw the graph using touch gesture, i

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.