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: 467 / 4866
Version history: 11 change(s)
Referenced in: [show references]