更新时间:2023-11-28 11:42:22
将按钮和标签添加到JPanel中,然后只需使JPanel不可见即可通过一次调用将其全部隐藏.
Add your buttons and labels to a JPanel and then you can simply make your JPanel invisible to hide them all with one call.
jPanel.setVisible(false);
或者,将按钮和标签添加到JComponent列表,然后遍历它:
Alternatively, add your buttons and labels to a JComponent list, and then loop through it:
List<JComponent> list = new ArrayList<JComponent>();
list.add(button);
list.add(label);
for(JComponent c : list){
c.setVisible(false);
}