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

29
LINES

< > BotCompany Repo | #1007748 // awtReplaceComponent

JavaX fragment (include)

1  
// makeNewComponent: func(Component) -> Component
2  
//                   or Component
3  
// returns new component
4  
static Component awtReplaceComponent(final Component c, fO makeNewComponent) {
5  
  if (c == null) null;
6  
  ret (Component) swing(func { 
7  
    Container parent = c.getParent();
8  
    if (parent == null) null;
9  
    Component[] l = parent.getComponents();
10  
    LayoutManager layout = parent.getLayout();
11  
    if (!(layout instanceof BorderLayout || layout instanceof ViewportLayout))
12  
      warn("awtReplaceComponent only tested for BorderLayout/ViewportLayout. Have: " + layout);
13  
    int idx = indexOf(l, c);
14  
    if (idx < 0) fail("component not found in parent");
15  
    //print("idx: " + idx);
16  
    //print("Parent: " + parent);
17  
    O constraints = callOpt(layout, "getConstraints", c);
18  
    //print("Constraints: " + constraints);
19  
    
20  
    // remove
21  
    parent.remove(c);
22  
  
23  
    // add new component  
24  
    Component newComponent = (Component) (makeNewComponent instanceof Component ? makeNewComponent :  callF(makeNewComponent, c));
25  
    parent.add(newComponent, constraints, idx);
26  
    validateFrame(parent);
27  
    ret newComponent;
28  
  });
29  
}

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: 649 / 660
Version history: 9 change(s)
Referenced in: [show references]