Nov 22, 2009

Create Dynamic Gui ?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > Java

Create Dynamic Gui ?

wutske
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 ?

Comment/Reply (w/o sign-up)

ethergeek
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.

Comment/Reply (w/o sign-up)

.:Brian:.
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?

Comment/Reply (w/o sign-up)

wutske
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 ?

 

 

 


Comment/Reply (w/o sign-up)

ethergeek
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.

Comment/Reply (w/o sign-up)

wutske
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

Comment/Reply (w/o sign-up)

Moo64c
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.

Comment/Reply (w/o sign-up)

wutske
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

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Dynamic Gui


    Looking for create, dynamic, gui,

See Also,

*SIMILAR VIDEOS*
Searching Video's for create, dynamic, gui,
advertisement



Create Dynamic Gui ?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com