How to iteratively add Components to a Swing GroupLayout ParallelGroup?

爱⌒轻易说出口 提交于 2019-11-29 14:24:37

I can see what you're trying to do and your confusion. You can only use anonymous class syntax with the new operator. i.e

new LinkedList<String>() {
  {
     add("bar");
  }
};

However ParallelGroup instances can only be created with the factory method createParallelGroup(...).

You'll have to use a temporary reference to the parallel group:

ParallelGroup pGroup = gl
        .createParallelGroup(GroupLayout.Alignment.CENTER);
hGroup.addGroup(pGroup);
for (JCheckBox c : listCustomiseJCB) {
    pGroup.addComponent(c);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!