Solved

replace checkboxs with buttons

Posted on 2004-04-10
3
171 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 96
printing a file in reverse order is easy in recursion rather than in iteration 3 56
stackato and cloud 4 85
hibernate insert example 13 28
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

776 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