sclass BetterLabel extends JLabel { bool autoToolTip = true; *() { // Listeners given out to componentPopupMenu must not directly // reference the outer object (-> weak map problem). final WeakReference 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 labels make super-huge, confusing tool tips setToolTipText(nullIfEmpty(text)); } } // moved outside of class for GC reasons (see above) static VF1 BetterLabel_menuItems(final WeakReference me) { ret voidfunc(JPopupMenu menu) { addMenuItem(menu, "Copy text to clipboard", r { copyTextToClipboard(me->getText()); }); }; }