是否有可以与GWT一起使用的进度条小部件,还是我必须自己制作?我试图在google-web-toolkit-incubator,gwtupload和upload4gwt中使用进度条而没有任何运气。
答案 0 :(得分:6)
一些代码:
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
public class ProgressBar extends Widget {
private static final String PERCENT_PATTERN = "#,##0%";
private static final NumberFormat percentFormat = NumberFormat.getFormat(PERCENT_PATTERN);
private final Element progress;
private final Element percentageLabel;
private double percentage;
private final double max;
public ProgressBar(double value, double max) {
assert max != 0;
this.max = max;
progress = DOM.createElement("progress");
progress.setAttribute("max", Double.toString(max));
progress.setAttribute("value", Double.toString(value));
percentageLabel = DOM.createElement("span");
percentage = value / max;
percentageLabel.setInnerHTML(percentFormat.format(percentage));
progress.insertFirst(percentageLabel);
setElement(progress);
}
public void setProgress(double value) {
progress.setAttribute("value", Double.toString(value));
percentage = value / max;
percentageLabel.setInnerHTML(percentFormat.format(percentage));
}
}
答案 1 :(得分:2)
我不知道您的要求,但HTML5支持进度条标记。这是一个简单的例子:
这是html:
<progress id="bar" value="0" max="100">
<span id="fallback">
<p>Your browser does not support progress tag.</p>
</span>
</progress>
以及用于查看其加载方式的脚本
<script>
window.onload = function() {
var bar = document.getElementById("bar"),
loaded = 0;
var load = function() {
loaded += 10;
bar.value = loaded;
if(loaded == 100) {
clearInterval(dummyLoad);
}
};
var dummyLoad = setInterval(function() {
load();
} ,1000);
}
</script>
其他信息:http://www.w3.org/wiki/HTML/Elements/progress 资料来源:http://www.onlywebpro.com/2011/09/09/html5-progress-bar/
答案 2 :(得分:1)
这是一个HTML5进度条示例:
在你的ui.xml中:
<progress ui:field="loadingProgress" style="width:100%" value="0" max="100"></progress>
在您的代码中:
@UiField Element loadingProgress;
loadingProgress.setPropertyInt("value", 50);