Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Graphics repaint() NOT Firing

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 ????


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,456
    My Mood
    Hungover
    Thanks
    144
    Thanked 638 Times in 546 Posts

    Default Re: Graphics repaint() NOT Firing

    I've moved this thread from the Member Introductions forum. Please read this: This Forum is for Saying Hi, not for Asking Technical Questions (READ BEFORE POSTING)

    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help with repaint
    By AraHabs in forum AWT / Java Swing
    Replies: 5
    Last Post: November 5th, 2011, 04:40 PM
  2. Graphics class NullPointerException Initialize Graphics Class??
    By bglueck in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 13th, 2011, 11:13 PM
  3. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 10:15 AM
  4. Repaint,
    By Time in forum AWT / Java Swing
    Replies: 3
    Last Post: May 21st, 2010, 11:23 PM
  5. Repaint doesn't repaint?
    By PotataChipz in forum AWT / Java Swing
    Replies: 6
    Last Post: January 18th, 2010, 08:56 PM