I took your advice and have been looking at the Grouped Layout Manager. The following code creates a 2 x 2 group of buttons, c0, c1, c2 and c3.
Everything works fine if the buttons are coded individually. However, if I try using a button array (btn[4]) and enter them via a for loop I get a runtime error.
Exception in
thread "main" java.lang.IllegalArgumentException: Component must be
non-null
at javax.swing.GroupLayout$ComponentSpring.<init>(GroupLayout.java:2953)
at javax.swing.GroupLayout$ComponentSpring.<init>(GroupLayout.java:2933)
at javax.swing.GroupLayout$Group.addComponent(GroupLayout.java:1524)
at javax.swing.GroupLayout$ParallelGroup.addComponent(GroupLayout.java:2484)
at javax.swing.GroupLayout$ParallelGroup.addComponent(GroupLayout.java:2454)
at javax.swing.GroupLayout$Group.addComponent(GroupLayout.java:1505)
at javax.swing.GroupLayout$ParallelGroup.addComponent(GroupLayout.java:2476)
at GroupedLayout2x2.<init>(GroupedLayout2x2.java:32)
at GroupedLayout2x2.main(GroupedLayout2x2.java:61)
The code is as follows:
Appreciate any help.