Programmatic HTMLDocument generation using Java

前端 未结 9 1883
孤独总比滥情好
孤独总比滥情好 2021-02-14 03:34

Does anyone know how to generate an HTMLDocument object programmatically in Java without resorting to generating a String externally and then using HTMLEditorKit#read to parse i

9条回答
  •  粉色の甜心
    2021-02-14 04:14

    It appears that you can accomplish what you are attempting using direct construction of HTMLDocument.BlockElement and HTMLDocument.BlockElement objects. Theses constructors have a signature that suggests direct use is possible, at least.

    I would suggest examining the Swing sources in OpenJDK to see how the parser handles this, and derive your logic from there.

    I would also suggest that this optimization may be premature, and perhaps this should be a speed-optimized replacement for a simpler approach (i.e. generating the HTML text) only introduced if this really does become a performance hotspot in the application.

提交回复
热议问题