JEditorPane () { JEditorPane editorPane = new JEditorPane() { JLabel myBaselineComponent; @Override public int getBaseline(int width, int height) { if (myBaselineComponent == null) { myBaselineComponent = new JLabel(); myBaselineComponent.setFont(getFont()); } myBaselineComponent.setText(getText()); Dimension size = myBaselineComponent.getPreferredSize(); return myBaselineComponent.getBaseline(size.width, size.height); } @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); if (size.height == 0) { size.height = getMinimumSize().height; } return size; } @Override public void updateUI() { super.updateUI(); setFont(StartupUiUtil.getLabelFont().deriveFont(Font.BOLD, 18)); } }; UIUtil.convertToLabel(editorPane); editorPane.setCaret(EmptyCaret.INSTANCE); editorPane.setFont(JBFont.create(StartupUiUtil.getLabelFont().deriveFont(Font.BOLD, 18))); @NlsSafe String text = "<html><span>Foo</span></html>"; editorPane.setText(text); editorPane.setMinimumSize(editorPane.getPreferredSize()); editorPane.setText(null); return editorPane; }