progressbar in javafx for loading a page

余生长醉 提交于 2019-12-11 22:38:34

问题


how to show a progress indicator till showing the other scene.? For example in login page after clicking on login button, progress indicator has to be displayed till the response from the other page. So the login page will go off and it will displays the new response page.


回答1:


It doesn't take much time at all to set up the UI and display it. So if there is a noticeable delay between clicking the login button and the "next page" being available, it is because you are doing some non-GUI time-consuming work as well (my best guess is that you're contacting a server to verify the login, but perhaps you are getting data too).

To do this, you need to put the time-consuming work into a Task and execute it on a different Thread. So when the user presses the login button:

  1. Display a progress bar
  2. Create a Task that does the time consuming work, and returns the results (if any)
  3. Set a handler for when the Task succeeds that creates the UI you want to show (using the data retrieved, if any), removes the progress bar, and displays the UI.
  4. Start the Task in another Thread

The API docs for the Task class have lots and lots of examples of using Tasks.



来源:https://stackoverflow.com/questions/22477294/progressbar-in-javafx-for-loading-a-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!