• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

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));
myArrayList.add(check);
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...
}
}
0
Drop_of_Rain
Asked:
Drop_of_Rain
  • 2
1 Solution
 
WebstormCommented:
Hi Drop_of_Rain,

Try this:

looprow:
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);

0
 
Drop_of_RainAuthor Commented:
I didn't know about looprow:

Thanks
0
 
WebstormCommented:
:-)

looprow: is a label which indicate which loop you want to break or continue, ...
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now