List of usage examples for javax.swing SwingUtilities layoutCompoundLabel
public static String layoutCompoundLabel(FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap)
From source file:net.sourceforge.processdash.ui.lib.chart.StandardDiscItemRenderer.java
protected void drawDiscLabel(Graphics2D g2, Ellipse2D shape, Paint labelPaint, Font labelFont, String label) { g2.setFont(labelFont);//from w ww.j ava 2 s.co m g2.setPaint(labelPaint); FontMetrics m = g2.getFontMetrics(); int height = m.getAscent(); double halfHeight = height / 2.0; double radius = shape.getWidth() / 2; double availableRadius = radius - getLabelPadding(); double halfWidth = Math.sqrt(availableRadius * availableRadius - halfHeight * halfHeight); int width = (int) Math.floor(halfWidth * 2 + 0.99); Rectangle viewR = new Rectangle(width, height); Rectangle iconR = new Rectangle(); Rectangle textR = new Rectangle(); String text = SwingUtilities.layoutCompoundLabel(m, label, null, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.TRAILING, viewR, iconR, textR, 0); if (text.equals(label) || text.length() >= 3 + minLabelChars) { double x = shape.getCenterX() - halfWidth + textR.x; double y = shape.getCenterY() + halfHeight + textR.y; g2.drawString(text, (float) x, (float) y); } }