
-----------------------------------
TokenHerbz
Sun Sep 30, 2012 12:18 am

I'm trying to find an easier way to populate alot of ComboBoxes.
-----------------------------------
I have this working when i write them all out and giving them all different names, However i wanted to try to use an array so that it saves alot of time.

However i'm unable to figure out how to get this to work.  Heres some code.
the commented out huge blocks work, but as you can see its alot of repeatingness, so i wanted to use an array (up at the top) to eliminate that issue.  thanks for helping :)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GamePanel extends JPanel {
    protected JPanel topLeftPanel, topMidPanel, topRightPanel,
                     botLeftPanel, botMidPanel, botRightPanel,
                     midLeftPanel, midMidPanel, midRightPanel;
    protected JPanel panel

-----------------------------------
2goto1
Sun Sep 30, 2012 12:33 pm

RE:I\'m trying to find an easier way to populate alot of ComboBoxes.
-----------------------------------
One issue looks like you're not assigning each panel[] and choice[] array element, and they arrays are not initially declared properly. 

The Java tutorial covers arrays enough to be able to do what you're trying to do, see http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html to get started.

-----------------------------------
TokenHerbz
Sun Sep 30, 2012 4:48 pm

RE:I\'m trying to find an easier way to populate alot of ComboBoxes.
-----------------------------------
I still can't get this working,

These don't error out but it doesn't look right
[code]
panel = new JPanel[9];
[/code]
it doesn't use the () which i thought was required.

However even with that working it doesn't for the ComboBoxes, you cant do the following
[code]
choice = new JComboBox(choiceOptions)[9];
//but you it doesn't error using
choice = new JComboBox[9];
//but then how do you add choiceOptions to it later?
[/code]

-----------------------------------
DemonWasp
Sun Sep 30, 2012 6:19 pm

RE:I\'m trying to find an easier way to populate alot of ComboBoxes.
-----------------------------------
You're creating 10 objects, not 1.


choice = new JComboBox

-----------------------------------
Beastinonyou
Sun Sep 30, 2012 6:38 pm

Re: I'm trying to find an easier way to populate alot of ComboBoxes.
-----------------------------------
I think you're confused as to how to go about creating an array of objects.
// This declares a variable 'panels' that references an array for JPanel. Note: Declaring an array reference variable does not create an array
JPanel

-----------------------------------
TokenHerbz
Mon Oct 01, 2012 7:44 pm

RE:I\'m trying to find an easier way to populate alot of ComboBoxes.
-----------------------------------
Haha awesome thank you.

I can't believe i got that all confused up...

...embarrassing :(
