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]
# 1
Try revalidate().
ajneoa at 2007-7-13 1:51:49 > top of Java-index,Desktop,Core GUI APIs...
# 2

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();

elwiza at 2007-7-13 1:51:49 > top of Java-index,Desktop,Core GUI APIs...
# 3

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.

JNameNotTakena at 2007-7-13 1:51:49 > top of Java-index,Desktop,Core GUI APIs...
# 4
I followed this example for my basic structure: http://forum.java.sun.com/thread.jspa?threadID=653369&messageID=3842056Is it the mysterious layeredPane that's mess my board up? I admit I don't know the nature of that component.
elwiza at 2007-7-13 1:51:49 > top of Java-index,Desktop,Core GUI APIs...
# 5
Better try to find my old example cause this makes no sense. My parent is a JPamnel (toSring tells me) buty it doesn't have the method !revalidate()"crazy :-(
elwiza at 2007-7-13 1:51:49 > top of Java-index,Desktop,Core GUI APIs...
# 6
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
elwiza at 2007-7-13 1:51:49 > top of Java-index,Desktop,Core GUI APIs...