java - How can I measure/calculate the size a Document needs to render itself? -
i have javax.swing.text.document , want calculate size of bounding box document needs render itself. is possible? it trivial plain text ( height = line count * line height , width = max width on each line ) how can rtf, html or other document? this code might give ideas: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class textpaneperfectsize extends jframe { jtextfield textfield; jtextpane textpane; public textpaneperfectsize() { textfield = new jtextfield(20); textfield.settext("add text"); getcontentpane().add(textfield, borderlayout.north ); textfield.addactionlistener( new actionlistener() { public void actionperformed(actionevent e) { try { document doc = textpane.getdocument(); doc.insertstring(doc.getlength(), " " + textfield.gettext()...