Content (@NotNull JTextComponent field, @NotNull Function<? super String, @Nls String> onShow) { Font font = field.getFont(); FontMetrics metrics = font == null ? null : field.getFontMetrics(font); int height = metrics == null ? 16 : metrics.getHeight(); Dimension size = new Dimension(height * 32, height * 16); JTextArea area = createTextArea(onShow.fun(field.getText()), field.isEditable(), field.getBackground(), field.getForeground(), font); copyCaretPosition(field, area); JLabel label = createLabel(createCollapseExtension()); label.setBorder(JBUI.Borders.empty(5, 0, 5, 5)); JBScrollPane pane = new JBScrollPane(area); pane.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS); pane.getVerticalScrollBar().add(JBScrollBar.LEADING, label); pane.getVerticalScrollBar().setBackground(area.getBackground()); Insets insets = field.getInsets(); Insets margin = field.getMargin(); if (margin != null) { insets.top += margin.top; insets.left += margin.left; insets.right += margin.right; insets.bottom += margin.bottom; } JBInsets.addTo(size, insets); JBInsets.addTo(size, pane.getInsets()); pane.setPreferredSize(size); pane.setViewportBorder(insets != null ? createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right) : createEmptyBorder()); return new Content() { @Override public @NotNull JComponent getContentComponent() { return pane; } @Override public JComponent getFocusableComponent() { return area; } @Override public void cancel(@NotNull Function<? super String, String> onHide) { if (field.isEditable()) { field.setText(onHide.fun(area.getText())); copyCaretPosition(area, field); } } }; }