summaryrefslogtreecommitdiff
path: root/src/swing
diff options
context:
space:
mode:
authorIngo Maier <ingo.maier@epfl.ch>2010-03-28 13:01:28 +0000
committerIngo Maier <ingo.maier@epfl.ch>2010-03-28 13:01:28 +0000
commita7dc91be7a1455bbeb05481357719d7247b596bd (patch)
tree0737fc93e0701de474d446afccc2efc2fe4d0023 /src/swing
parent25d87efb94582184b7f2a4f4a29838364a113f15 (diff)
downloadscala-a7dc91be7a1455bbeb05481357719d7247b596bd.tar.gz
scala-a7dc91be7a1455bbeb05481357719d7247b596bd.tar.bz2
scala-a7dc91be7a1455bbeb05481357719d7247b596bd.zip
Fix for #2980. No review.
Diffstat (limited to 'src/swing')
-rw-r--r--src/swing/scala/swing/BorderPanel.scala8
-rw-r--r--src/swing/scala/swing/LayoutContainer.scala7
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 }