0

I have a standard paintComponent() method that draw some shapes on a Swing JPanel, via Java2D.

Initially, the JPanel surface is displayed with a clean white background.

After the user select a file, I build the shapes (in a separated thread) based on the instructions on the file.

Then, I call JPanel's rapaint() method, you know, will be handled at the EDT.

I can tell when the repaint() processing ends: I just need to look at the new drawings on the screen.

So, this morning I don't have many ideas to answer THE QUESTION: how to know the same information via code?

ranieribt
  • 1,280
  • 1
  • 15
  • 33
  • 1
    Can't you just add a notifier at the end of your paintComponent? – Dariusz Feb 06 '13 at 15:07
  • The notifier was just the boolean value returned by Graphics#drawImage()! Worked fine. – ranieribt Feb 06 '13 at 16:15
  • That's one option, but using it means that you have to periodically check the value of that variable in the other thread. I would have considered some more sophisticated solution, but if it works for you then I suppose it's ok. – Dariusz Feb 06 '13 at 16:24

1 Answers1

2

You don't have any automatic notification, but you can set a boolean variable or call a method at the end of your paintComponent().

Note that normally you should not have this problem, because paintComponent() is supposed to contain only code that executes fast, any initialization/calculation should be moved to another method.

lbalazscs
  • 17,474
  • 7
  • 42
  • 50
  • Thank you! I think a 'boolean variable' or a 'method call' can be tested with Graphics#drawImage() or with ImageObserver#imageUpdate() to help notify me about the pixels loaded on screen. Let me see, right now... – ranieribt Feb 06 '13 at 15:41
  • Hey @Iblalazscs, solved with the boolean value returned by drawImage at the end of the paintComponent() – ranieribt Feb 06 '13 at 16:16
  • If you have a BufferedImage, then drawImage should always return true (and you can use null as the ImageObserver). Anyway, if the answer was correct, you should accept it :) – lbalazscs Feb 06 '13 at 16:21