Java JComponent Size getPreferredSize(String html, boolean width, int prefSize)

Here you can find the source of getPreferredSize(String html, boolean width, int prefSize)

Description

get Preferred Size

License

Open Source License

Declaration

public static java.awt.Dimension getPreferredSize(String html, boolean width, int prefSize) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.JLabel;

import javax.swing.text.View;

public class Main {
    static final JLabel resizer = new JLabel();

    public static java.awt.Dimension getPreferredSize(String html, boolean width, int prefSize) {
        resizer.setText(html);//from ww  w.j  av  a 2 s .  com
        View view = (View) resizer.getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey);
        view.setSize(width ? prefSize : 0, width ? 0 : prefSize);
        float w = view.getPreferredSpan(View.X_AXIS);
        float h = view.getPreferredSpan(View.Y_AXIS);
        return new java.awt.Dimension((int) Math.ceil(w), (int) Math.ceil(h));
    }
}

Related

  1. getComponentOfSameSize(final JComponent c)
  2. getLocalScreenSize(Component invoker)
  3. getMaxSize(JComponent[] components)
  4. getOptimalScreenSize(Container container, Dimension currentDim)
  5. getPreferredSize(JComponent component, int width)
  6. getPreferredSize(Window window)
  7. getPreferredSizeComponent(JComponent component)
  8. getScreenSize()
  9. getScreenSize(Component invoker)