removing Labels
*BAA*
I'm so mad cause I know I fixed this before - but I can't figure out how.
I have a panel (chessboard) with instances of JLabels(chesspieces) on it, and I want to remove some of them now and then. Simply doing a
"
chessPiece.setVisible(false);
parent.remove(chessPiece);
"
will not do. The ImageIcon of my chessPiece is still there.. Guess I need to do somekind of update?
Regards
[443 byte] By [
elwiza] at [2007-10-2 10:21:09]

Thanks for answering.
Didn't have "revalidate" on my Component only parent.validate() but that didn't help.
Which object should revalidate what? Guess my problem is what my parent actually is..
public void mouseReleased(MouseEvent e)
{
if (chessPiece == null) return;
chessPiece.setVisible(false);
Component c = chessBoard.findComponentAt(e.getX(), e.getY());
if (c instanceof JLabel)
{
Container parent = c.getParent();
You should probably call
chessBoard.revalidate();
chessBoard.repaint();
after each move.
Now, I don't know what chessBoard is but assuming it's a Container of some kind, if you add or remove components from it. then invoking the above methods should make all changes visible. It's like a 'refresh' thing.
Ok - whatever, my layeredPane did do it (it seems).layeredPane.remove(chessPiece);layeredPane.revalidate();layeredPane.repaint();All I needed was a cheeseburger to make my brain start working.(it looks like the .getParent() version didn't work