javafx中用于加载页面的进度条 [英] progressbar in javafx for loading a page

查看:2566
本文介绍了javafx中用于加载页面的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示进度指示器,直到显示另一个场景。例如,在点击登录按钮后的登录页面中,必须显示进度指示器,直到来自另一页面的响应。所以登录页面将会关闭,它将显示新的响应页面。

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.

推荐答案

它不需要花费太多时间设置UI并显示它。因此,如果单击登录按钮和下一页之间存在明显的延迟,那是因为您正在进行一些非GUI耗时的工作(我最好的猜测是您正在联系服务器验证登录,但也许你也得到了数据。)

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).

要做到这一点,你需要将耗时的工作放入一个Task并在另一个上执行线。因此,当用户按下登录按钮时:

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. 显示进度条

  2. 创建一个任务花费
    的时间是否有效,并返回结果(如果有的话)

  3. 设置一个处理程序,当任务成功时创建你想要显示的UI(b $ b)使用检索到的数据(如果有),删除
    进度条,并显示UI。

  4. 在另一个线程中启动任务

  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

API任务类的文档有很多很多使用任务的例子。

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

这篇关于javafx中用于加载页面的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆