How to determine preferred size

I have a custom ToolTip which is displaying a JTextPane. The JTextPane contains HTML formatted text.

How can I best determine the preferred size for the JTextPane and for the JToolTip? The HTML text needs

to be word wrapped on the JTextPane - which is why I am setting the preferred size on the JTextPane.

Currently I am hard coding the preferred size, but this isn't practical since many different beans are using my custom ToolTip.

Any suggestions or advice would be appreciated.

Thanks.

[529 byte] By [baddog2a] at [2007-9-30 2:21:07]
# 1
also, just to add to that. I have a predefined width for the JTextPane, I just need a way to calculate the height. I could try a little math based on the length of the text and the width, but some HTML tags add in a new line, so my display gets truncated.
baddog2a at 2007-7-16 13:30:17 > top of Java-index,Archived Forums,Swing...
# 2
bump
baddog2a at 2007-7-16 13:30:17 > top of Java-index,Archived Forums,Swing...
# 3

Here is the solution.

preferredWidth is the predefined width I want to use. The height needed to take into consideration new lines of HTML code.

View v = textpane.getUI().getRootView(textpane);

v.setSize(preferredWidth , Integer.MAX_VALUE);

int preferredHeight = (int) v.getPreferredSpan(View.Y_AXIS);

textpane.setPreferredSize(new Dimension(preferredWidth, preferredHeight ));

baddog2a at 2007-7-16 13:30:17 > top of Java-index,Archived Forums,Swing...