From 0f732a6453da4fa4d8b563ee4a8a0f85901dad48 Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 14 Aug 2003 22:05:07 +0000 Subject: [PATCH] A JLayeredPane that gets around an awt/swing bug by removing all popups whenever any component is removed. Whee. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1198 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/swing/SafeLayeredPane.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 projects/samskivert/src/java/com/samskivert/swing/SafeLayeredPane.java diff --git a/projects/samskivert/src/java/com/samskivert/swing/SafeLayeredPane.java b/projects/samskivert/src/java/com/samskivert/swing/SafeLayeredPane.java new file mode 100644 index 00000000..fe86e955 --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/swing/SafeLayeredPane.java @@ -0,0 +1,39 @@ +// +// $Id: SafeLayeredPane.java,v 1.1 2003/08/14 22:05:07 ray Exp $ + +package com.samskivert.swing; + +import java.awt.Component; +import javax.swing.JLayeredPane; + +/** + * A JLayeredPane that removes all popups when any component is removed. + * This gets around an apparent bug in awt/swing that fucks up hard when + * a component is removed and a popup is up. + */ +public class SafeLayeredPane extends JLayeredPane +{ + public void remove (int index) + { + Component c = getComponent(index); + + // remove all popups + boolean removedPops = false; + for (int ii=getComponentCount() - 1; ii >= 0; ii--) { + if (getLayer(getComponent(ii)) == POPUP_LAYER.intValue()) { + super.remove(ii); + removedPops = true; + } + } + + // if we removed any popups, the index may have changed so we + // need to remove by reference + if (removedPops) { + remove(c); // which will end up calling this method again, but + // the second time the popups will already be gone + + } else { + super.remove(index); + } + } +}