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]

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.
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 ));