Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java array help

Name: Anonymous 2010-07-30 21:13

hey /prog/ just wondering if anyone could give me a hand with some java code. Basically I am trying to place labels from an array of JLabels into a JPanel using .add, but it doesn't want to work. I have never used an array of JLabels before, so i am certain that i fucked up somewhere.

Code:

public void setProp() {

        for (int i = 0; i < label.length; i++) {
            label[i] = new JLabel("");
            label[i].setPreferredSize(labelDim);
            label[i].setIcon(new ImageIcon(this.getClass().getResource("blank.gif")));
            label[i].setEnabled(true);
            label[i].setVisible(false);
            pnlMap.add(label[i]);

        }
    }


also blank.gif is just a black square and the dimensions are set to match the icon dimensions.

any input would be appreciated

Name: Anonymous 2010-07-30 22:24

>>3
You're probably getting the IllegalArgumentException from the method addImpl(Component comp, Object constraints, int index) for which add(Component comp) is a convenience method.  Read your Javadocs about that.

Without knowing more about what you did to pnlMap, all you can do to help is post the whole class this method is in, and the the stack trace (error message).

Just as a suggestion, also use setSize(Dimension) method along with setPreferredSize(Dimension).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List