Change the numbers of the chechboxs

Hello everyone out there, another question.

How could I get the numbers to start at 1 and end in 50
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyClass4 extends JPanel {

ArrayList myArrayList = new ArrayList();

// Constructor
public MyClass4() {
// JPanel myPanel = new JPanel(); // No JPanel - why do we need it? I'M a JPanel...
setLayout(new GridLayout(0,3)); // Setting MY layout...
for (int row=0; row<20; row++) {
for(int col=0; col<3; col++) {
JCheckBox check = new JCheckBox("" + (20*col+row));
add(check); // Adding it to ME
// myPanel.setLayout(new FlowLayout()); Why would I change the layout back to FlowLayout? All hell would break loose...
// add(myPanel); Don't need it at it's ME...
Who is Participating?
WebstormConnect With a Mentor Commented:
Hi Drop_of_Rain,

Try this:

for (int row=0; row<20; row++) {
for(int col=0; col<3; col++) {
int n=(20*col+row+1);
if (n>50) break looprow;
JCheckBox check = new JCheckBox("" + n);

Drop_of_RainAuthor Commented:
I didn't know about looprow:


looprow: is a label which indicate which loop you want to break or continue, ...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.