Articles Projects Tips Downloads Contacts About

JEditorPane's content height for fixed width.

To provide correct layout of JEditorPane's content we need to know what height we will have for the content if JEditorPane's width is fixed. The code below can be used to measure JEditorPane and JTextPane.

    public static int getContentHeight(String content) {
        JEditorPane dummyEditorPane=new JEditorPane();
        return dummyEditorPane.getPreferredSize().height;

    int h=getContentHeight("Long text to be measured in the JEditorPane");