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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:40:17+00:00 2026-05-16T01:40:17+00:00

I’ve been trying for hours to get my drawing method to work by drawing

  • 0

I’ve been trying for hours to get my drawing method to work by drawing in a BufferedImage stored in a Clojure ref, and then to have that painted onto the component (in this case a JPanel) in order to display it. Unfortunately, this isn’t working well at all.

My code is this (pared down, but showing the relevant parts:

(defn create-graph
  "Data-ref is [xs ys], buffered-image-ref holds the basic graph."
  [data-ref buffered-image-ref & {:keys [width height image]}]
  (proxy [JPanel]
      []
    (getPreferredSize [] (Dimension. width  height))
    (paintComponent [g]
                    (proxy-super paintComponent g)
                    (if-not @buffered-image-ref
                      (dosync
                       (ref-set buffered-image-ref
                                (xy-plot2
                                 (first @data-ref)
                                 (second @data-ref)
                                 (.getGraphics
                                  (BufferedImage. width height 
                                                  BufferedImage/TYPE_INT_ARGB))
                                 :axis? true
                                 :width width
                                 :height height))))
                    (.drawImage g @buffered-image-ref
                                0 0 
                                (proxy [ImageObserver]
                                         []
                                       (imageUpdate []
                                          (proxy-super imageUpdate)))))))

And, below, xy-plot2 (which doesn’t appear to be the problem, but I’ll include it for completeness:

(defn xy-plot2
  "Draws an xy-plot in the given Graphics context.
   'xs must be equal in length to 'ys."
  [xs ys gfx
   & {:keys [color max-y axis? y-buffer width height]
     :or {color Color/RED y-buffer 0}}]
  (let [h (/ height 2) ;; since we have -h to h (not 0 to h)
        w width ;; since we graph 0 to w
        len (count xs)
        min-x (apply min xs)
        xs (if-not (zero? min-x)
             (map #(- % min-x) xs)
             xs)
        max-y (or max-y (apply max ys))
        max-x (apply max xs)]
    (.setColor gfx color)
    (dorun ;; this is the key part, along with scale-xs and draw-l
     (take len
           (iterate (partial d-line gfx h)
                    [(scale-xs xs w 0)
                     (scale-xs ys h y-buffer)])))
    (and axis? (or (.setColor gfx Color/BLACK) (.drawLine gfx 0 h w h)))
    gfx))

When I run this, I get this error, which leads to to believe I’ve messed up in the last part of the paintComponent() method.

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException:
No matching method found: drawImage for class sun.java2d.SunGraphics2D

I’ve tried substituting nil for the ImageObserver, but to no avail. I’ve tried other arg orders (for other drawImage methods for other types of Graphics classes). All to no avail.

Sorry if I’m sounding a bit hard to understand, this bug’s been plaguing me. I’ll edit in the morning, if need be!

Thank you so, so much,
Isaac

  • 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-16T01:40:18+00:00Added an answer on May 16, 2026 at 1:40 am

    It looks like buffered-image-ref is set to the graphics of the BufferedImage, not the image itself.

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

Sidebar

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.