Click to See Complete Forum and Search --> : JLabel question


Splatt
October 4th, 2000, 01:29 PM
Is there any reason you can't use a JLabel more than once in the same JPanel? I can't seem to. For example:

JLabel testLabel = new JLabel("T");
testLabel.setForeground(Color.black);
testLabel.setFont(stdFont);
this.add(testLabel);

//I add a JTextField here

this.add(testLabel);

//I add a JTextField here

this.add(testLabel);



doesn't work. Only the last added JLabel will appear. Does anyone know a way around this?


"There's nothing more dangerous than a resourceful idiot." ---Dilbert

laneh
October 4th, 2000, 03:57 PM
make a second jLabel

"There are no facts, only interpretations."
-Friedrich Nietzsche

laneh
October 4th, 2000, 04:04 PM
I just realized that I didn't give you any explaination..
You'll need a different JLabel for each label you put on the GUI. It is because each item on the GUI is an object w/ specific properties (such as size, position on screen, etc.) And you can't have one object in more than one place at any time.. that is why you need to have the extra jLabels, even if they say the same thing

"There are no facts, only interpretations."
-Friedrich Nietzsche