我已经宣布了一个JLable如下;
l = new JLabel("Hello");
l.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(l);
Run Code Online (Sandbox Code Playgroud)
现在,我想隐藏或删除它.应该叫什么方法?
我试过l.removeAll();<---什么都没有.
还有一个calle remove(int)接受一个int.但我不知道该作为参数传递什么.
还有一些叫做的东西hide().但是它被弃用了.
Run Code Online (Sandbox Code Playgroud)i tried l.removeAll(); <--- nothing hapend.
你需要打电话remove就JPanel其JLabel加入到:
panel.remove(l);
//after that you need to call this to revalidate and repaint the panel
panel.revalidate();
panel.repaint();
Run Code Online (Sandbox Code Playgroud)
只是隐藏而不是删除电话
l.setVisible(false);
Run Code Online (Sandbox Code Playgroud)