Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Create Dynamic Gui ?
wutske
post Nov 5 2007, 09:00 AM
Post #1


Way Out Of Control - You need a life :)
Group Icon

Group: [HOSTED]
Posts: 1,048
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 mellow.gif .
My first tought was to create an array of checkboxes, but this doesn't seem to work ohmy.gif .

Any ideas ?
Go to the top of the page
 
+Quote Post
ethergeek
post Nov 5 2007, 03:03 PM
Post #2


Premium Member
Group Icon

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.
Go to the top of the page
 
+Quote Post
.:Brian:.
post Nov 5 2007, 04:05 PM
Post #3


Premium Member
Group Icon

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?
Go to the top of the page
 
+Quote Post
wutske
post Nov 5 2007, 04:20 PM
Post #4


Way Out Of Control - You need a life :)
Group Icon

Group: [HOSTED]
Posts: 1,048
Joined: 2-August 05
From: Kapellen (Antwerp, Belgium)
Member No.: 7,585



I think the cold classroom was freezing my brains a bit rolleyes.gif . It is possible to create an array of checkboxes and I did it this way (it's still very basic):

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 dry.gif

@ethergeek: I know vectors are more dynamic then arrays, but are there any other advantagen when using them ?
Go to the top of the page
 
+Quote Post
ethergeek
post Nov 5 2007, 05:53 PM
Post #5


Premium Member
Group Icon

Group: [HOSTED]
Posts: 393
Joined: 9-March 07
From: Tucson, AZ
Member No.: 20,794



QUOTE(wutske @ Nov 5 2007, 09:20 AM) *
@ethergeek: I know vectors are more dynamic then arrays, but are there any other advantagen when using them ?


Lots. smile.gif
  • They're thread safe
  • They're easier to work with
  • Parameterized, there's no casting needed like there was in 1.4-
  • Serialize easier
  • Implement most of the collections interfaces, so you get sorting, iterating, serialization...right out of the box
  • Built in batch methods for adding collections to collections
Object oriented collections almost always have an advantage over simple collections like arrays. The notable exception here is arrays of primitives...you can't make collections of primitives, so the JVM has to autobox/unbox them when you try...this can be slow if done in a large loop.

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
Go to the top of the page
 
+Quote Post
wutske
post Nov 7 2007, 08:12 AM
Post #6


Way Out Of Control - You need a life :)
Group Icon

Group: [HOSTED]
Posts: 1,048
Joined: 2-August 05
From: Kapellen (Antwerp, Belgium)
Member No.: 7,585



Allright, crap ohmy.gif , I still have a lot of things to learn about java wacko.gif , EDT, serlialization wacko.gif ...

I think I'll spend my weekend reading, reading and more reading tongue.gif

//edit: as soon as I've found out how to use vector, I'll implement them in my program smile.gif , don't want to write a crappy project, going for at least 18/20 tongue.gif

This post has been edited by wutske: Nov 7 2007, 08:13 AM
Go to the top of the page
 
+Quote Post
Moo64c
post May 30 2008, 02:43 PM
Post #7


Newbie [ Level 1 ]
Group Icon

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.
Go to the top of the page
 
+Quote Post
wutske
post May 30 2008, 05:40 PM
Post #8


Way Out Of Control - You need a life :)
Group Icon

Group: [HOSTED]
Posts: 1,048
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 smile.gif .
Also, watch out for bumping old topics, the mods don't like it if you do it too often wink.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How to create a guestbook with php !!!(7)
  2. Create Ur Own Avatar(12)
  3. How To: Create PDF With Php(18)
  4. Create Your Own Shout Box(13)
  5. How Do I Create A Good Fire Animation Using Flash ?(13)
  6. Help Needed To Create Login Script With Perl/cgi(21)
  7. How To Create "ghost" Images (norton) On Windows(47)
  8. You Cannot Create A File Named Con(9)
  9. How To Create Your Own MSN Winks ?(10)
  10. Create A Site Without Cms But Just Dreamweaver?(6)
  11. Help Me Create A Text-based, Turn-based Game(10)
  12. I Want To Create A PHP Text Based Web Game(5)
  13. Create And Import JavaScript Modules For A Large Script(2)
  14. How To Create Exe File In Java?(13)
  15. The Cloning Issue(43)
  1. Can You Create A Folder Name "con"(18)
  2. New Browser Based Game, Create Or Conquer(4)
  3. How Do I Create Static Routes In Windows Xp?(11)
  4. How To Create Your Own Proxy Site (free And Easy)(13)
  5. Easiest Free Forum To Create Custom Skin For?(2)
  6. Dynamic Gd Image(2)
  7. How To Create A "user Profile" Page.(14)
  8. Dynamic Php Image And Better Php Code Question(10)
  9. How Do You Create A Vista?(21)
  10. Create An Animation With Powerpoint(1)
  11. Create An Ftp Server On Your Pc With Serv-u(1)
  12. What You Need Before You Can Create A Text-based Game..(7)
  13. [c/c++][linux] Linking With A -l Is Static Or Dynamic?(0)


 



- Lo-Fi Version Time is now: 13th October 2008 - 09:26 PM