void () { try { super.dispose(); for (Map.Entry<JLayeredPane, JComponent> entry : myMap.entrySet()) { JLayeredPane layeredPane = entry.getKey(); layeredPane.remove(entry.getValue()); layeredPane.revalidate(); layeredPane.repaint(); } } finally { myMap.clear(); } }