From a7dc91be7a1455bbeb05481357719d7247b596bd Mon Sep 17 00:00:00 2001 From: Ingo Maier Date: Sun, 28 Mar 2010 13:01:28 +0000 Subject: Fix for #2980. No review. --- src/swing/scala/swing/BorderPanel.scala | 8 +++++++- src/swing/scala/swing/LayoutContainer.scala | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/swing/scala/swing/BorderPanel.scala b/src/swing/scala/swing/BorderPanel.scala index 2acc56787b..01fe873f93 100644 --- a/src/swing/scala/swing/BorderPanel.scala +++ b/src/swing/scala/swing/BorderPanel.scala @@ -51,5 +51,11 @@ class BorderPanel extends Panel with LayoutContainer { wrapPosition(layoutManager.getConstraints(comp.peer).asInstanceOf[String]) protected def areValid(c: Constraints): (Boolean, String) = (true, "") - protected def add(c: Component, l: Constraints) { peer.add(c.peer, l.toString) } + protected def add(c: Component, l: Constraints) { + // we need to remove previous components with the same constraints as the new one, + // otherwise the layout manager loses track of the old one + val old = layoutManager.getLayoutComponent(l.toString) + if(old != null) peer.remove(old) + peer.add(c.peer, l.toString) + } } diff --git a/src/swing/scala/swing/LayoutContainer.scala b/src/swing/scala/swing/LayoutContainer.scala index b58064ed07..8e94bf565f 100644 --- a/src/swing/scala/swing/LayoutContainer.scala +++ b/src/swing/scala/swing/LayoutContainer.scala @@ -42,7 +42,10 @@ trait LayoutContainer extends Container.Wrapper { protected def areValid(c: Constraints): (Boolean, String) /** * Adds a component with the given constraints to the underlying layout - * manager and the component peer. + * manager and the component peer. This method needs to interact properly + * with method `constraintsFor`, i.e., it might need to remove previously + * held components in order to maintain layout consistency. See `BorderPanel` + * for an example. */ protected def add(comp: Component, c: Constraints) @@ -53,7 +56,7 @@ trait LayoutContainer extends Container.Wrapper { * * layout(myComponent) = myConstraints * - * also ensures that myComponent is properly add to this container. + * also ensures that myComponent is properly added to this container. */ def layout: Map[Component, Constraints] = new Map[Component, Constraints] { def -= (c: Component): this.type = { _contents -= c; this } -- cgit v1.2.3