# Java JLayeredPane - remove a JLabel



## jfm429 (Jun 8, 2007)

I'm trying to remove a JLabel from a layer in a JLayeredPane. How do I do this? I've tried:

```
contentPane.remove(aJLabelComponent);
```
and:

```
contentPane.remove(contentPane.getIndexOf(aJLabelComponent));
```
and neither worked. Calling validate afterwards didn't help. What am I doing wrong here?


----------



## gdi1942 (Nov 2, 2006)

I've used layered panes before. Are you sure the layered pane is the problem?
Try removing an object at say position 1 so contentPane.remove(1); and see if the object actually disappears, maybe the problem is somewhere else.

Also i found http://java.sun.com/j2se/1.5.0/docs/api/ very useful for configureing my layered pane. You may also have to call repaint on the pane.


----------



## gdi1942 (Nov 2, 2006)

Had an epiphany, you must make sure you add it in the right mannor, the add() overriden method doesn't do what you expect in this scenario. To add a component you must specify the integer of the position in the layer you want to object to appear. If you just call add on it's own, the object is actually sitting on top of the layered pane.


----------



## jfm429 (Jun 8, 2007)

Fixed it, just had to call repaint()
duh.
Thanks for the advice!


----------

