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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:37:12+00:00 2026-06-15T21:37:12+00:00

I have difficulties drawing an image on a JFreeChart – XYLineChart. The main problem

  • 0

I have difficulties drawing an image on a JFreeChart – XYLineChart. The main problem is the x and y coordinates of the annotation is updated dynamically in real time.So with my code adding the annotation and clearing it for the new one to be drawn causes flickering which is annoying for the user.

I have checked some examples of flickering problems on JAVA using update() , paint () or repaint() methods using graphics but seems not implementable on a JFreeChart.

Do you have any ideas how to get rid of the flicker or a workaround to use one bufferedImage on the JFreeChart instead of an annotation ?

To be more specific here is the drawn line and the image :

Screenshot

So this cross hair (as the buffered image) should go on the plot line up and down with the updated values of x and y axis.But this motion causes the flickering unfortunately.

Here is the part of my code where I draw the image – I cannot provide SSCCE I guess since there are more than 15 classes and 5k of written code :

// After a button clicked on panel
SomeButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {

        // The chart and XYPlot is already drawn at this point 


        // Reading the image
        try {
            myPicture = ImageIO
                    .read(new File("\\\\Users2\\blabla\\Data\\MyPictures\\x.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Setting up a timer
        timer2 = new java.util.Timer();

        Object source = event.getSource();
        if (source == SomeButton) {

        // Setting up a task
            task2 = new java.util.TimerTask() {
                @Override
                public void run() {
                    double x1;
                    double y1;
                    try {
                        // Getting different x and y values from a microcontroller instantaneously
                        if (microContConnected()) {

                            x1 = microCont.getX();
                            y1 = microCont.getY();

                            // creating the annotation
                            XYImageAnnotation ImageAnn = new XYImageAnnotation(x1, y1, myPicture);

                            // Here is the drawing and clearing made !
                            plot.addAnnotation(ImageAnn);       
                            pause(50);
                            plot.clearAnnotations();    
                        }

                    } catch (SerialPortException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            };
            timer2.scheduleAtFixedRate(task2, 50, 50);
        }
    }
});
  • 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-06-15T21:37:13+00:00Added an answer on June 15, 2026 at 9:37 pm

    It seems I found a solution myself ; instead of adding the image to plot I use the renderer and there is no pause function between adding and removing the picture with new coordinates.. also sequence of adding and removed are reversed. Surprising for me to work this way I must say. There is no flickering left; it’s as smooth as a clipped graphics or double buffered. 🙂 Here is the new code :

        // renderer
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    
        // Reading the image
        try {
            myPicture = ImageIO.read(new File("\\\\Users2\\blabla\\Data\\MyPictures\\x.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        // Setting up a timer
        timer2 = new java.util.Timer();
    
        Object source = event.getSource();
        if (source == someButton) {
    
                    task2 = new java.util.TimerTask() {
                        @Override
                        public void run() {
                            if (check == true) {
                                if (microContConnected()) {
    
                                     x1 = microCont.getX();
                                     y1 = microCont.getY();
    
                                    renderer.removeAnnotations();
    
                                    XYImageAnnotation img2 = new XYImageAnnotation(
                                            x1, y1, myPicture);
                                    renderer.addAnnotation(img2,
                                            Layer.FOREGROUND);
                                }
                            }
                        }
                    };
                    timer2.scheduleAtFixedRate(task2, 50, 50);
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having difficulties drawing an image in an NSRect, the code below creates an
I have difficulties with implementing Holding event on Image in a Metro app. <Image
I am have difficulties solving this problem: For a positive number n, define C(n)
I have difficulties understanding a problem I encountered during instantiation of a QT class
I sometimes have difficulties with other people who wish to solve a problem when
I'm French so my English is quite bad but I have a real problem
I have difficulties developing 4x1 widget for Android. This is the appprovider <?xml version=1.0
I know this question had been asked a hundred times, but I have difficulties
I am reading the book: Intel Threading Building Blocks. I often have difficulties understanding
I have some difficulties with understanding BindingSource's behaviour. Let's look at following example: Creating

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.