/** * 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); float h = view.getPreferredSpan(View.Y_AXIS); return new Dimension((int) Math.ceil(w), (int) Math.ceil(h)); }
@Override public void setSize(float width, float height) { super.setSize(width, height); updateMetrics(); }
/** * Helper method for {@linkplain #getHtmlLabelTextExtent(java.lang.String, int, boolean)}. This * is required because we are creating and invisibly rendering a {@code JLabel} object in this * method, and being virtuous in our Swing usage we should only do that on the event dispatch * thread. * * @param labelText the text to render, optionally enclosed in {@code <html>...</html>} tags * @param fixedDimSize the size of the fixed dimension (either width or height * @param width {@code true} if the fixed dimension is width; {@code false} for height * @return the rendered label text extent */ private static Dimension doGetHtmlTextExtent( String labelText, int fixedDimSize, boolean width) { final JLabel label = new JLabel(); if (labelText.startsWith("<html>")) { label.setText(labelText); } else { label.setText("<html>" + labelText + "</html>"); } View view = (View) label.getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey); view.setSize(width ? fixedDimSize : 0, width ? 0 : fixedDimSize); 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)); } }
@Override public void setSize(float width, float height) { setSizeRunning = true; try { this.width = (int) width; view.setSize(width, height); } finally { setSizeRunning = false; } }
/** * Sets the view size. * * @param width the width * @param height the height */ @Override public void setSize(float width, float height) { this.width = (int) width; view.setSize(width, height); }
/** * Sets the view size. * * @param width the width * @param height the height */ public void setSize(float width, float height) { if (view != null) { view.setSize(width, height); } }
/** * Sets the view size. * * @param width the width * @param height the height */ @Override public void setSize(float width, float height) { this.width = (int) width; view.setSize(width, height); }
/** * Sets the view size. * * @param width the width * @param height the height */ @Override public void setSize(float width, float height) { this.width = (int) width; view.setSize(width, height); }
/** * Sets the view size. * * @param width the width * @param height the height */ @Override public void setSize(float width, float height) { this.width = (int) width; view.setSize(width, height); }
/** * Sets the view size. * * @param width the width * @param height the height */ @Override public void setSize(float width, float height) { this.width = (int) width; view.setSize(width, height); }
@Override public void paint(Graphics g, Shape allocation) { Rectangle alloc = allocation.getBounds(); view.setSize(alloc.width, alloc.height); view.paint(g, allocation); }
/** * Renders the view. * * @param g the graphics context * @param allocation the region to render into */ @Override public void paint(Graphics g, Shape allocation) { Rectangle alloc = allocation.getBounds(); view.setSize(alloc.width, alloc.height); view.paint(g, allocation); }
@Override public void setSize(float width, float height) { super.setSize(width, height); updateMetrics(); }
/** * Renders the view. * * @param g the graphics context * @param allocation the region to render into */ @Override public void paint(Graphics g, Shape allocation) { Rectangle alloc = allocation.getBounds(); view.setSize(alloc.width, alloc.height); view.paint(g, allocation); }
/** * Renders the view. * * @param g the graphics context * @param allocation the region to render into */ @Override public void paint(Graphics g, Shape allocation) { Rectangle alloc = allocation.getBounds(); view.setSize(alloc.width, alloc.height); view.paint(g, allocation); }
/** * Renders the view. * * @param g the graphics context * @param allocation the region to render into */ @Override public void paint(Graphics g, Shape allocation) { Rectangle alloc = allocation.getBounds(); view.setSize(alloc.width, alloc.height); view.paint(g, allocation); }
/** * Renders the view. * * @param g the graphics context * @param allocation the region to render into */ @Override public void paint(Graphics g, Shape allocation) { Rectangle alloc = allocation.getBounds(); view.setSize(alloc.width, alloc.height); view.paint(g, allocation); }
public void setSize(float width, float height) { lock(); try { if (view != null) { view.setSize(width, height); } } finally { unlock(); } }
JLabel labelBeingUsed = myLabel; View view = (View) labelBeingUsed.getClientProperty(BasicHTML.propertyKey); view.setSize(scrollPane1.getWidth(), 0.0f); float w = view.getPreferredSpan(View.X_AXIS); float h = view.getPreferredSpan(View.Y_AXIS); labelBeingUsed.setSize((int) w, (int) h);
JLabel labelBeingUsed = myLabel; View view = (View) labelBeingUsed.getClientProperty(BasicHTML.propertyKey); view.setSize(scrollPane1.getWidth(), 0.0f); float w = view.getPreferredSpan(View.X_AXIS); float h = view.getPreferredSpan(View.Y_AXIS); labelBeingUsed.setSize((int) w, (int) h);