sclass BetterLabel extends JLabel { bool autoToolTip = true; *() { // Listeners given out to componentPopupMenu must not directly // reference the outer object (-> weak map problem). final WeakReference refThis = new(this); componentPopupMenu(this, voidfunc(JPopupMenu menu) { addMenuItem(menu, "Copy text to clipboard", r { copyTextToClipboard(refThis.getText()); }); }); } *(S text) { 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(text); } }