How to reset JLabel
问题 I am trying to reset an array of JLabels. There are images on the top of the labels so when i press a button the labels are supposed to be reset. I tried to do it like that for(int i=0; i<desks.length; i++) { desks[i].setText(""); rightPanel.add(desks[i]); } so if anyone have an idea it would be great.cheers. 回答1: this is one of possible ways int n = panel.getComponentCount(); if (n > 0) { Component[] components = panel.getComponents(); for (int i = 0; i < components.length; i++) { if