// makeNewComponent: func(Component) -> Component // or Component // returns new component static Component awtReplaceComponent(final Component c, fO makeNewComponent) { if (c == null) null; ret (Component) swing(func { Container parent = c.getParent(); if (parent == null) null; Component[] l = parent.getComponents(); LayoutManager layout = parent.getLayout(); if (!(layout instanceof BorderLayout || layout instanceof ViewportLayout)) warn("awtReplaceComponent only tested for BorderLayout/ViewportLayout. Have: " + layout); int idx = indexOf(l, c); if (idx < 0) fail("component not found in parent"); //print("idx: " + idx); //print("Parent: " + parent); O constraints = callOpt(layout, "getConstraints", c); //print("Constraints: " + constraints); // remove parent.remove(c); // add new component Component newComponent = (Component) (makeNewComponent instanceof Component ? makeNewComponent : callF(makeNewComponent, c)); parent.add(newComponent, constraints, idx); validateFrame(parent); ret newComponent; }); }