How to Hide or remove a JLabel

java, jlabel, swing

Solution

i tried l.removeAll(); <--- nothing hapend.

you need to call to `remove` on `JPanel` which the `JLabel` was added to :

panel.remove(l);

//after that you need to call this to revalidate and repaint the panel
panel.revalidate(); 
panel.repaint();

just to hide and not to remove call

l.setVisible(false);

Problem

I have declared a JLable as follows; ``` l = new JLabel("Hello"); l.setHorizontalAlignment(SwingConstants.CENTER); panel.add(l); ``` Now, i want to hide or remove it. What should be the method i should call ? i tried `l.removeAll();` <--- nothing hapend. there's another one calle `remove(int)` which takes an int. But i am not sure what to pass as the parameter. There's also something called `hide()`. but it's deprecated.

Original source