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)

1  
sclass BetterLabel extends JLabel {
2  
  bool autoToolTip = true;
3  
  
4  
  *() {
5  
    // Listeners given out to componentPopupMenu must not directly
6  
    // reference the outer object (-> weak map problem).
7  
    final WeakReference<BetterLabel> me = new(this);
8  
    componentPopupMenu(this, BetterLabel_menuItems(me));
9  
  }
10  
  
11  
  *(S text) {
12  
    this();
13  
    this.setText(text);
14  
  }
15  
  
16  
  public void setText(S text) {
17  
    super.setText(text);
18  
    if (autoToolTip)
19  
      if (!swic(text, "<html>")) // HTML labels make super-huge, confusing tool tips
20  
        setToolTipText(nullIfEmpty(text));
21  
  }
22  
}
23  
24  
// moved outside of class for GC reasons (see above)
25  
static VF1<JPopupMenu> BetterLabel_menuItems(final WeakReference<BetterLabel> me) {
26  
  ret voidfunc(JPopupMenu menu) {
27  
    addMenuItem(menu, "Copy text to clipboard", r {
28  
      copyTextToClipboard(me->getText());
29  
    });
30  
  };
31  
}

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