How to iteratively add Components to a Swing GroupLayout ParallelGroup?

后端 未结 1 1375
醉话见心
醉话见心 2020-12-20 23:24

Is there a way to iterate over a List of Components and add them to a ParallelGroup in Swing GroupLayout?

It seems difficult because there is no method to get hold

相关标签:
1条回答
  • 2020-12-21 00:05

    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);
    }
    
    0 讨论(0)
提交回复
热议问题