Search in sources :

Example 81 with View

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));
}
Also used : Dimension(java.awt.Dimension) View(javax.swing.text.View)

Aggregations

View (javax.swing.text.View)81 Rectangle (java.awt.Rectangle)8 HTMLDocument (javax.swing.text.html.HTMLDocument)6 Dimension (java.awt.Dimension)5 Element (javax.swing.text.Element)5 FontMetrics (java.awt.FontMetrics)4 Insets (java.awt.Insets)4 UIResource (javax.swing.plaf.UIResource)4 Point (java.awt.Point)3 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)3 Color (java.awt.Color)2 Font (java.awt.Font)2 Graphics2D (java.awt.Graphics2D)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Border (javax.swing.border.Border)2 BadLocationException (javax.swing.text.BadLocationException)2 ViewFactory (javax.swing.text.ViewFactory)2 JBColor (com.intellij.ui.JBColor)1 JBGradientPaint (com.intellij.ui.JBGradientPaint)1