Graphics repaint() NOT Firing
Consider the code below for a graphics class that will be used for painting a time-series chart. For now it just prints "painting"
public class ChartingPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
System.out.println("painting");
}
}
This function is used elsewhere in my program. It has a static call and is on a thread.
public void historicalData(int reqId, String date, double open, double high, double low,
double close, int volume, int count, double WAP, boolean hasGaps) {
System.out.println(date + " " + open + " " + high + " " + low + " " + close);
chartingPanel.repaint();
}
What I want to happen is to generate a printout like this:
20120614 06:00:00 1.25565 1.2586 1.2553 1.25705
painting
20120614 07:00:00 1.25705 1.25785 1.25555 1.2567
painting
20120614 08:00:00 1.2567 1.2589 1.2551 1.2579
painting
20120614 09:00:00 1.2579 1.2601 1.25635 1.25995
painting
What's happening is a printout like this:
painting
painting
20120607 17:15:00 1.2561 1.2565 1.25605 1.2564
20120607 18:00:00 1.2564 1.25715 1.2563 1.25685
painting
20120607 19:00:00 1.25685 1.2575 1.25665 1.2568
20120607 20:00:00 1.2568 1.2572 1.25295 1.254
painting
20120607 21:00:00 1.254 1.25425 1.25225 1.25245
20120607 22:00:00 1.25245 1.2529 1.25145 1.2528
painting
20120607 21:00:00 1.254 1.25425 1.25225 1.25245
20120607 22:00:00 1.25245 1.2529 1.25145 1.2528
20120607 23:00:00 1.2528 1.2533 1.25215 1.25215
20120608 00:00:00 1.25215 1.2529 1.2518 1.25245
---------------------------------------------------------------------------------
Some sort of synchronization issue with the Graphics. The repaint() method is not firing for every time the historicalData is called. What can I do to fix this ????
Re: Graphics repaint() NOT Firing
I've moved this thread from the Member Introductions forum. Please read this: http://www.javaprogrammingforums.com...e-posting.html
Also, please use highlight tags when posting code.
You don't have control over when a component is painted- it can happen when the window is moved, resized, or whenever Java feels like it. Also, you can't guarantee that every call to repaint() will result in an actual call to paintComponent() - several calls to repaint() can be rolled up into one actual paint event, for example.
There are way around these things, but I think in your case the answer is to reexamine your design.