我有一个名为 LMSPanel 的类,它扩展了 JPanel。这个类有以下两个方法:
/**
* A method to add an informative temporary label to the Panel until
* the second Sensor is added.
*
* @param zoneid - The ID of the Zone.
* @param sensorid - The ID of the Sensor.
*/
public void justAddedLbl(String zoneid, String sensorid)
{
infoLbl = new JLabel("Sensor: " + zoneid + sensorid + " added. Please Add 2nd Sensor.");
add(infoLbl);
revalidate();
}
/**
* A method to remove the temporary informative label.
* Only called when second sensor has been added.
*/
public void removeInfoLbl()
{
remove(infoLbl);
revalidate();
}
添加方法工作正常,但是当我尝试调用removeInfoLbl
标签时,标签会保留并消失。我已经尝试过repaint()
在网上找到的各种组合,但仍然无法删除 JLabel。
我究竟做错了什么?