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.

sclass SingleComponentPanel extends JPanel {
  *() { super(new BorderLayout); }

  *(Component component) {
    this();
    if (component != null) setComponent(component);
  }
  
  void set(Swingable component) {
    set(wrap(component));
  }

  void setComponent aka set(Component component) {
    swing {
      if (getComponent() == component) ret;
      
      removeAll();
      if (component != null)
        add(BorderLayout.CENTER, wrap(component));
      _revalidate(SingleComponentPanel.this);
    }
  }
  
  // Sometimes we need this?
  void setComponentAndRevalidateParent(Component component) {
    setComponent(component);
    _revalidate(_getParent(this));
  }
  
  void noComponent aka clear() { setComponent(null); }
  
  Component getComponent aka get() {
    ret swing( -> getComponentCount() == 0 ? null : getComponent(0));
  }
  
  bool isEmpty() { ret getComponent() == null; }
  bool hasComponent() { ret getComponent() != null; }
}

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: 824 / 5763
Version history: 20 change(s)
Referenced in: #1019849 - Loadable Utils
#1029927 - Loadable Utils v2 (old)
#1030952 - Loadable Utils for Gazelle BEA [LIVE, see #1030953, edited by #1030951]
#1031186 - Loadable Utils v5
#1032272 - Loadable Utils for Gazelle BEA [backup]
#1032708 - Secret BEA Utils [purposely different from regular utils]
#1033505 - Loadable Utils for Gazelle V [stable version]
#1033861 - Loadable Utils for Gazelle 22 [dev version]
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)