use of javax.swing.text.View in project GCViewer by chewiebug.
the class AboutDialog method calculatePreferredSize.
/**
* Returns the preferred size to set a component at in order to render
* an html string. You can specify the size of one dimension.
*
* @see <a href="http://blog.nobel-joergensen.com/2009/01/18/changing-preferred-size-of-a-html-jlabel/">reference for this implementation</a>
*/
private Dimension calculatePreferredSize(JLabel labelWithHtmlText, boolean width, int preferredSize) {
View view = (View) labelWithHtmlText.getClientProperty(BasicHTML.propertyKey);
view.setSize(width ? preferredSize : 0, width ? 0 : preferredSize);
float w = view.getPreferredSpan(View.X_AXIS);
// add 10% to compensate for high dpi screens with jdk 11
float h = view.getPreferredSpan(View.Y_AXIS) * (float) 1.1;
return new Dimension((int) Math.ceil(w), (int) Math.ceil(h));
}
Aggregations