简体   繁体   English

在不了解进度的情况下更新JProgressBar

[英]Update JProgressBar Without Knowing Progress

I want to use a JProgressBar but I don't have any measurement of progress for how long the task will take to complete. 我想使用JProgressBar,但我没有任何关于完成任务需要多长时间的进度测量。 The idea is to have a progress bar displaying the status of a shutdown process but I don't know how long it takes, and I have no way of editing the class that does the shutdown process. 我的想法是有一个显示关闭过程状态的进度条,但我不知道它需要多长时间,而且我无法编辑执行关闭过程的类。

Is there a way to use a JProgressBar without having any indication of the progress? 有没有办法使用JProgressBar而没有任何进展指示?

Call setIndeterminate(true) . 调用setIndeterminate(true)

From the javadocs : 来自javadocs

To indicate that a task of unknown length is executing, you can put a progress bar into indeterminate mode. 要指示正在执行未知长度的任务,可以将进度条置于不确定模式。 While the bar is in indeterminate mode, it animates constantly to show that work is occurring. 当条形图处于不确定模式时,它会不断动画以显示正在进行的工作。 As soon as you can determine the task's length and amount of progress, you should update the progress bar's value and switch it back to determinate mode. 只要您可以确定任务的长度和进度,就应该更新进度条的值并将其切换回确定模式。

You can have a JProgressBar which displays in indeterminate mode, as described here . 你可以有一个JProgressBar ,显示不确定模式,如所描述这里 The default animation is a 'bouncer,' that is, the progress indicator will go back and forth between the two ends of the bar until you stop it. 默认动画是'保镖',也就是说,进度指示器将在条形图的两端之间来回移动,直到您停止它为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM