void (ActionButton button) { if (button != null && button.getParent() != null) { Container parent = button.getParent(); parent.remove(button); //noinspection RedundantCast ((JComponent)parent).revalidate(); parent.repaint(); } }