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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With