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

  • SEARCH
  • Home
  • 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 7947157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:21:08+00:00 2026-06-04T01:21:08+00:00

I have a Java FX 2 app which is updating hundreds of times a

  • 0

I have a Java FX 2 app which is updating hundreds of times a second.
I’m getting a problem where the labels are partially blanked for a fraction of a second but this happens fairly often.
How do I fix this?

enter image description here

  • 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-04T01:21:10+00:00Added an answer on June 4, 2026 at 1:21 am

    Calling Platform.runLater() hundreds of times a second is not a good idea. I advise you throttle the input speed of your data source or batch your data together before invoking Platform.runLater() to update your UI, such that Platform.runLater isn’t invoked > 30 times a second.

    I filed a jira request RT-21569 to improve the documentation on the Platform.runLater call and consider implementing a superior runLater event throttling system in the underlying platform.

    A sample solution for batching runLater events is given by Richard Bair in this forum thread.

    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.scene.Scene;
    import javafx.scene.control.ListView;
    import javafx.stage.Stage;
    
    import java.util.LinkedList;
    import java.util.List;
    import java.util.concurrent.Semaphore;
    
    /**
     *
     */
    public class BackgroundLoadingApp extends Application {
    
        private ListView<String> listView;
    
        private List<String> pendingItems;
    
        private Semaphore lock = new Semaphore(1);
    
        protected void addItem(String item) throws InterruptedException {
            if (Platform.isFxApplicationThread()) {
                listView.getItems().add(item);
            } else {
                // It might be that the background thread
                // will update this title quite frequently, and we need
                // to throttle the updates so as not to completely clobber
                // the event dispatching system.
                lock.acquire();
                if (pendingItems == null) {
                    pendingItems = new LinkedList<String>();
                    pendingItems.add(item);
                    Platform.runLater(new Runnable() {
                        @Override public void run() {
                            try {
                                lock.acquire();
                                listView.getItems().addAll(pendingItems);
                                pendingItems = null;
                            } catch (InterruptedException ex) {
                                ex.printStackTrace();
                            } finally {
                                lock.release();
                            }
                        }
                    });
                } else {
                    pendingItems.add(item);
                }
                lock.release();
            }
        }
    
        /**
         * The main entry point for all JavaFX applications.
         * The start method is called after the init method has returned,
         * and after the system is ready for the application to begin running.
         * <p/>
         * <p>
         * NOTE: This method is called on the JavaFX Application Thread.
         * </p>
         *
         * @param primaryStage the primary stage for this application, onto which
         *                     the application scene can be set. The primary stage will be embedded in
         *                     the browser if the application was launched as an applet.
         *                     Applications may create other stages, if needed, but they will not be
         *                     primary stages and will not be embedded in the browser.
         */
        @Override public void start(Stage primaryStage) throws Exception {
            listView = new ListView<String>();
            primaryStage.setScene(new Scene(listView));
            primaryStage.show();
    
            // Start some background thread to load millions of rows as fast as it can. But do
            // so responsibly so as not to throttle the event thread
            Thread th = new Thread() {
                @Override public void run() {
                    try {
                        for (int i=0; i<2000000; i++) {
                            addItem("Item " + i);
                            if (i % 200 == 0) {
                                Thread.sleep(20);
                            }
                        }
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                }
            };
            th.setDaemon(true);
            th.start();
        }
    
        public static void main(String[] args) {
            launch(args);
        }
    }
    

    Comments by Richard Bair copied from the referred forum thread:

    Here is an example that simulates some long running thread producing copious amounts of data.
    I found that it wasn’t working quite to my liking. If the Thread.sleep is missing, it still swamps the process (perhaps it is the way I’m handling the concurrency in this case). I also found if I reduced it to “2” ms of sleeping then I couldn’t grab the scroll bar thumb and move it around. I think the problem here is that there is a mouse event in the event queue for the press and drag, but between drag events new items are added to the list causing the thumb to move and since this happens more frequently than my drag events the thumb never goes where I want it to be. This I think is due to the way the thumb position is handled based on the number of rows, not sure what can be done about it except for the application to throttle and batch up the rows being added as I do here.

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

Sidebar

Related Questions

I have a Swing runnable app which updates messages, then I have a Java
I have a Java application which is running as non root mode. My App
I have done simple java app for blackberry, while building am getting following error.
I have a Java app which reads CSV files which have been created in
I have a Java app which needs to interact with the camera on a
Let's say I have a Java app which uses a (static) int constant from
i am making a app which takes photo on button click i have camera.java
We have a java app which we call with a parameter (a selected folder),
I have written a relatively simple Java App Engine application which I would like
I have a java app in which I use a thread. My thread runs

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.