Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

29
LINES

< > BotCompany Repo | #1007748 // awtReplaceComponent

JavaX fragment (include)

// 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;
  });
}

Author comment

Began life as a copy of #1007747

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007748
Snippet name: awtReplaceComponent
Eternal ID of this version: #1007748/10
Text MD5: 809ba5ade742e3b21421602616c6caa0
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-15 17:05:30
Source code size: 1160 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 650 / 660
Version history: 9 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1008237 - replaceComponent - synonym of awtReplaceComponent