Solved

replace checkboxs with buttons

Posted on 2004-04-10
3
172 Views
Last Modified: 2010-03-31
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...
}
}
0
Comment
Question by:Drop_of_Rain
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 10796103
replace:

JCheckBox check = new JCheckBox("" + n);

with:

JButton check = new JButton("" + n);
0
 

Author Comment

by:Drop_of_Rain
ID: 10796111
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 10796158
Don't worry, I'm a patient man :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question