我想添加一个文本区域,用户可以在进度条更新时看到我在控制台中可以看到的一些信息。
如何添加文字区域?
以下是我用于制作进度条的代码示例。我可以在进度条下方添加应该填充的文本区域,而计算是主要的吗?
<div id="main-body">
<ul class="nav-tabs">
<li class="active-tab"><a href="#">Home</a>
</li>
<li><a href="#">Menu 1</a>
</li>
<li><a href="#">Menu 2</a>
</li>
</ul>
</div>
<div id="right-wrap">
<div id="right-menu"></div>
</div>
答案 0 :(得分:0)
尝试向任务的messageProperty添加一个侦听器,只要文本被更改,它就会将文本附加到TextArea。
TextArea ta = new TextArea();
public void activateTextArea(final Task<?> task) {
task.messageProperty().addListener((property, oldValue, newValue) -> {
ta.setText(ta.getText() + "\n" + newValue);
});
}
然后在任务中加入这样的东西:
Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
for (int i = 0; i < 10; i++) {
updateProgress(i, 10);
updateMessage((i*10) + "% done");
Thread.sleep(200);
}
updateProgress(10, 10);
updateMessage("All done!");
return null;
}
};
答案 1 :(得分:0)
在使用Labelled
而不是您想要使用的文字Label
之前,您是否听说过Label
Node
并在您想要的时候写下您的文字显示您的Progressbars
Label.setGraphic(myprogressbarNode);
希望有所帮助
编辑
我想添加一个文本区域,用户可以在进度条更新时看到我可以在控制台中看到的一些信息...我可以在进度条下面添加应该填充的文本区域,而计算是母马?
我给你一个解决方案。
假设您拥有ProgressBar
pb
;并且您将ProgressBar添加到StackPane
,而不是直接添加ProgressBar
,而是添加Text
,您将Label
添加Label
所以假设您的lb
{1}} StackPane sp; // parent
ProgressBar pb; // progress indicator
Lable lb; // my text area
sp.getChildren().add(lb);// i have added the text area
lb.setGraphic(pb); we have added the progressbar to the text area
lb.setContentDisplay(ContentDisplay.***);//the *** represents the position you want your graphic
//whether top or left or bottom
//now you are done, your pb will show aligned to your lb, and be updated
//if you want to show text lb.setText("your text");
这就是您的代码的样子
{{1}}
这是多么隐含? : - )