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

31
LINES

< > BotCompany Repo | #1011150 // BetterLabel - JLabel with automatic tooltip and popup menu

JavaX fragment (include)

sclass BetterLabel extends JLabel {
  bool autoToolTip = true;
  
  *() {
    // Listeners given out to componentPopupMenu must not directly
    // reference the outer object (-> weak map problem).
    final WeakReference<BetterLabel> me = new(this);
    componentPopupMenu(this, BetterLabel_menuItems(me));
  }
  
  *(S text) {
    this();
    this.setText(text);
  }
  
  public void setText(S text) {
    super.setText(text);
    if (autoToolTip)
      if (!swic(text, "<html>")) // HTML labels make super-huge, confusing tool tips
        setToolTipText(nullIfEmpty(text));
  }
}

// moved outside of class for GC reasons (see above)
static VF1<JPopupMenu> BetterLabel_menuItems(final WeakReference<BetterLabel> me) {
  ret voidfunc(JPopupMenu menu) {
    addMenuItem(menu, "Copy text to clipboard", r {
      copyTextToClipboard(me->getText());
    });
  };
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1011150
Snippet name: BetterLabel - JLabel with automatic tooltip and popup menu
Eternal ID of this version: #1011150/12
Text MD5: 7e8b63d2ea1bcf79fcd2d395ddb27799
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-28 16:41:21
Source code size: 894 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 462 / 4860
Version history: 11 change(s)
Referenced in: #1016582 - Global Utils (stuff in here gets moved to x30_pkg.x30_util.*)
#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)