Solved

replace checkboxs with buttons

Posted on 2004-04-10
3
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 76
by zero exception 10 83
sql import cannot be resolved jsp 3 117
restrict decimal places for double datatype 10 49
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
This video teaches viewers about errors in exception handling.
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.
Suggested Courses

739 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