诀窍是使用GlyphVector。 每个字母必须单独移动和旋转。
public class HalfCircleDemo {
@SuppressWarnings("serial")
private static class DemoPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics = (Graphics2D) g ;
graphics.setPaint(Color.yellow);
graphics.fill(new Rectangle(0, 0, 100, 100));
graphics.fill(new Rectangle(100, 100, 200, 200));
graphics.setPaint(Color.BLACK);
{ /* THIS IS THE SECTION THAT DOES THE WORK *******************************************/
Font font = graphics.getFont();
FontRenderContext frc = graphics.getFontRenderContext();
GlyphVector glyphVector = font.createGlyphVector(frc, str);
int glyphCount = str.length();
int radius = 50 ;
for (int i=0 ; i
double theta = Math.PI * i