|
|
|
|
![]() ![]() |
Nov 5 2007, 09:00 AM
Post
#1
|
|
|
Way Out Of Control - You need a life :) Group: [HOSTED] Posts: 1,025 Joined: 2-August 05 From: Kapellen (Antwerp, Belgium) Member No.: 7,585 |
I'm currently working on a small project for school. I need to place a variable amount of checkboxes in a jPanel, but I have no idea how to start
My first tought was to create an array of checkboxes, but this doesn't seem to work Any ideas ? |
|
|
|
Nov 5 2007, 03:03 PM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 393 Joined: 9-March 07 From: Tucson, AZ Member No.: 20,794 |
You can stick them in an array to keep track of them (though if it's variable, I would use Vector<JCheckBox> to store them. Then just iterate across the array to add them to the form.
|
|
|
|
Nov 5 2007, 04:05 PM
Post
#3
|
|
|
Premium Member Group: Members Posts: 219 Joined: 13-February 07 Member No.: 20,371 |
Can't you use an arrayList or something to store checkbox objects (and add them and such)?
I am not sure as I haven't ever done any GUI programming in java, so I don't know too much about it, but I would assume you could use an arrayList to store the objects and keep track of them somehow? |
|
|
|
Nov 5 2007, 04:20 PM
Post
#4
|
|
|
Way Out Of Control - You need a life :) Group: [HOSTED] Posts: 1,025 Joined: 2-August 05 From: Kapellen (Antwerp, Belgium) Member No.: 7,585 |
I think the cold classroom was freezing my brains a bit
CODE private void generateComponents() { JCheckBox[] seat_checks; seat_checks = new JCheckBox[6]; for (int i=0;i<6;i++) { seat_checks[i] = new JCheckBox("seat " + String.valueOf(i)); checkspanel.add(seat_checks[i]); } } Still don't know why it didn't work this morning @ethergeek: I know vectors are more dynamic then arrays, but are there any other advantagen when using them ? |
|
|
|
Nov 5 2007, 05:53 PM
Post
#5
|
|
|
Premium Member Group: [HOSTED] Posts: 393 Joined: 9-March 07 From: Tucson, AZ Member No.: 20,794 |
@ethergeek: I know vectors are more dynamic then arrays, but are there any other advantagen when using them ? Lots.
Edit: I forgot to mention: when updating a GUI on the fly, it's a good idea to pass it off to the Event Dispatch Thread (EDT) so as to avoid painting inconsistencies. This is easily done using the SwingUtilities.invokeAndWait() method. This post has been edited by ethergeek: Nov 5 2007, 05:55 PM |
|
|
|
Nov 7 2007, 08:12 AM
Post
#6
|
|
|
Way Out Of Control - You need a life :) Group: [HOSTED] Posts: 1,025 Joined: 2-August 05 From: Kapellen (Antwerp, Belgium) Member No.: 7,585 |
Allright, crap
I think I'll spend my weekend reading, reading and more reading //edit: as soon as I've found out how to use vector, I'll implement them in my program This post has been edited by wutske: Nov 7 2007, 08:13 AM |
|
|
|
May 30 2008, 02:43 PM
Post
#7
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 8 Joined: 30-May 08 Member No.: 30,660 |
I have no idea what is the vector thing, but I'd go for an ArrayList<JCheckBox>. It's as dynamic as you'd need.
for example: Adding a checkbox will result in: 1. extending the gui screen a bit more 2. adding the checkbox to the ArrayList 3. adding the checkbox to the gui. etc. |
|
|
|
May 30 2008, 05:40 PM
Post
#8
|
|
|
Way Out Of Control - You need a life :) Group: [HOSTED] Posts: 1,025 Joined: 2-August 05 From: Kapellen (Antwerp, Belgium) Member No.: 7,585 |
Moo64c, this topic is almost one year old, I've turned the application in a long time ago
Also, watch out for bumping old topics, the mods don't like it if you do it too often |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th September 2008 - 05:18 AM |