Link to home
Start Free TrialLog in
Avatar of Drop_of_Rain
Drop_of_Rain

asked on

replace checkboxs with buttons

Wound there be a way of recreating ythe code below #1 using new JButton(""); instead of checkboxs. There is a space limitation and this would save from having to write a lot of repetitive code.

Code #1

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...
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);

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...
}
}
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Drop_of_Rain
Drop_of_Rain

ASKER

Thanks, you make it look so simple to me.
I know I have problems asking my questions sometimes, just be patient with me.

Could you look at a question we were working on together earlier please.

linking two sets of code together I think I have made it clear now.
Don't worry, I'm a patient man :)