Widgets: fix Z-Order on up/down mouse events
authorNiki Roo <niki@nikiroo.be>
Tue, 4 Jul 2017 05:59:28 +0000 (07:59 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 4 Jul 2017 05:59:28 +0000 (07:59 +0200)
src/jexer/TWidget.java

index 9b99c915e92ab217fc250b6197d4d80620933297..d4ec1e2ba9ae8cfc23fb5eaac9d03915125d880b 100644 (file)
@@ -868,7 +868,8 @@ public abstract class TWidget implements Comparable<TWidget> {
      */
     public void onMouseDown(final TMouseEvent mouse) {
         // Default: do nothing, pass to children instead
-        for (TWidget widget: children) {
+       for (int i = children.size() - 1 ; i >= 0 ; i--) {
+               TWidget widget = children.get(i);
             if (widget.mouseWouldHit(mouse)) {
                 // Dispatch to this child, also activate it
                 activate(widget);
@@ -889,7 +890,8 @@ public abstract class TWidget implements Comparable<TWidget> {
      */
     public void onMouseUp(final TMouseEvent mouse) {
         // Default: do nothing, pass to children instead
-        for (TWidget widget: children) {
+       for (int i = children.size() - 1 ; i >= 0 ; i--) {
+               TWidget widget = children.get(i);
             if (widget.mouseWouldHit(mouse)) {
                 // Dispatch to this child, also activate it
                 activate(widget);