JBLabel (boolean copyable) { if (copyable ^ myEditorPane != null) { if (myEditorPane == null) { final JLabel ellipsisLabel = new JBLabel("..."); myIconLabel = new JLabel(getIcon()); myEditorPane = new JEditorPane() { @Override public void paint(Graphics g) { Dimension size = getSize(); boolean paintEllipsis = getPreferredSize().width > size.width && !myMultiline && !myAllowAutoWrapping; if (!paintEllipsis) { super.paint(g); } else { Dimension ellipsisSize = ellipsisLabel.getPreferredSize(); int endOffset = size.width - ellipsisSize.width; try { // do not paint half of the letter endOffset = modelToView(viewToModel(new Point(endOffset, getHeight() / 2)) - 1).x; } catch (BadLocationException ignore) { } Shape oldClip = g.getClip(); g.clipRect(0, 0, endOffset, size.height); super.paint(g); g.setClip(oldClip); g.translate(endOffset, 0); ellipsisLabel.setSize(ellipsisSize); ellipsisLabel.paint(g); g.translate(-endOffset, 0); } } }; myEditorPane.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (myEditorPane == null) return; int caretPosition = myEditorPane.getCaretPosition(); myEditorPane.setSelectionStart(caretPosition); myEditorPane.setSelectionEnd(caretPosition); } }); myEditorPane.setContentType("text/html"); myEditorPane.setEditable(false); myEditorPane.setBackground(UIUtil.TRANSPARENT_COLOR); myEditorPane.setOpaque(false); myEditorPane.addHyperlinkListener(createHyperlinkListener()); ComponentUtil.putClientProperty(myEditorPane, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Collections.singleton(ellipsisLabel)); myEditorPane.setEditorKit(HTMLEditorKitBuilder.simple()); updateEditorPaneStyle(); if (myEditorPane.getCaret() instanceof DefaultCaret) { ((DefaultCaret)myEditorPane.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } myEditorPane.setText(getText()); checkMultiline(); myEditorPane.setCaretPosition(0); updateLayout(); updateTextAlignment(); // Remove label from tab order because selectable labels doesn't have visible selection state setFocusTraversalPolicyProvider(true); setFocusTraversalPolicy(new DisabledTraversalPolicy()); } else { removeAll(); myEditorPane = null; myIconLabel = null; } } return this; }