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

38
LINES

< > BotCompany Repo | #1005319 // SingleComponentPanel

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (7066L) is out of date.

1  
sclass SingleComponentPanel extends JPanel {
2  
  *() { super(new BorderLayout); }
3  
4  
  *(Component component) {
5  
    this();
6  
    if (component != null) setComponent(component);
7  
  }
8  
  
9  
  void set(Swingable component) {
10  
    set(wrap(component));
11  
  }
12  
13  
  void setComponent aka set(Component component) {
14  
    swing {
15  
      if (getComponent() == component) ret;
16  
      
17  
      removeAll();
18  
      if (component != null)
19  
        add(BorderLayout.CENTER, wrap(component));
20  
      _revalidate(SingleComponentPanel.this);
21  
    }
22  
  }
23  
  
24  
  // Sometimes we need this?
25  
  void setComponentAndRevalidateParent(Component component) {
26  
    setComponent(component);
27  
    _revalidate(_getParent(this));
28  
  }
29  
  
30  
  void noComponent aka clear() { setComponent(null); }
31  
  
32  
  Component getComponent aka get() {
33  
    ret swing( -> getComponentCount() == 0 ? null : getComponent(0));
34  
  }
35  
  
36  
  bool isEmpty() { ret getComponent() == null; }
37  
  bool hasComponent() { ret getComponent() != null; }
38  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005319
Snippet name: SingleComponentPanel
Eternal ID of this version: #1005319/21
Text MD5: 101946a9ed62ae2d9d02ee6444873bf9
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-03 23:50:02
Source code size: 991 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 825 / 5764
Version history: 20 change(s)
Referenced in: [show references]