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

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.

主站蜘蛛池模板: 广饶县| 水富县| 鹿邑县| 土默特右旗| 孝昌县| 麻江县| 赤壁市| 乃东县| 郁南县| 武功县| 九台市| 靖安县| 龙州县| 搜索| 清流县| 黄陵县| 离岛区| 新宾| 中超| 米泉市| 镇江市| 桦甸市| 甘谷县| 中西区| 江口县| 那曲县| 合山市| 毕节市| 赤峰市| 观塘区| 茶陵县| 松原市| 天气| 赣州市| 广昌县| 确山县| 本溪| 太仓市| 屏东县| 永嘉县| 县级市|