官术网_书友最值得收藏!

Time for action – showing the results

The default behavior of the application is to show only the results of the last execution. We need to remove all the results that have been previously added to the resultsLayout component if the user has not checked Keep previous results. To do that, implement your showResults method:

private void showResults(Collection<String> results) {
  if(!checkBox.getValue()) {
    resultsLayout.removeAllComponents();
    
  } else if(resultsLayout.getComponentCount() > 0) {
    resultsLayout.addComponent(new Label("--"));
  }
  
  for(String result : results) {
    resultsLayout.addComponent(new Label(result));
  }
}

What just happened?

If the checkbox is not checked, we can remove all the components in resultsLayout (not in layout, we don't want baffled users here):

resultsLayout.removeAllComponents();

If we don't have to remove previous results, we add a separator and iterate over the results to add each one using a label.

Tip

You can remove single components from layouts using the removeComponent method:

layout.removeComponent(someComponent);

Congratulations! We have finished a useful application. Try implementing your own test sets and learn more about Java performance.

主站蜘蛛池模板: 井研县| 福海县| 建阳市| 延庆县| 通辽市| 浏阳市| 英德市| 息烽县| 九龙县| 喀什市| 宜川县| 岚皋县| 遵义市| 合水县| 榆社县| 闸北区| 晋中市| 诸暨市| 平遥县| 江孜县| 都江堰市| 平昌县| 吉安县| 巴马| 清新县| 林口县| 上虞市| 桃园市| 新丰县| 故城县| 洱源县| 龙口市| 香格里拉县| 阜新| 通许县| 富源县| 射阳县| 芷江| 宁武县| 新宁县| 滦平县|