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

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.

主站蜘蛛池模板: 将乐县| 东莞市| 大庆市| 藁城市| 佛山市| 旺苍县| SHOW| 武川县| 高阳县| 临西县| 杭锦旗| 达拉特旗| 洪泽县| 永清县| 黔江区| 兖州市| 新巴尔虎左旗| 泸州市| 通化县| 通城县| 宿松县| 晋州市| 城固县| 共和县| 崇州市| 汪清县| 乐都县| 垦利县| 洛扎县| 家居| 磐石市| 南阳市| 蓝山县| 保康县| 龙泉市| 米脂县| 双桥区| 枝江市| 鲜城| 伊吾县| 桂阳县|