的Java:调整边框的宽度

问题描述:

我用这个代码:勾勒字体:的Java:调整边框的宽度

public class MyText extends JPanel { 
String text1 = null; 
public MyText (String text) { 
text1 = text; 
} 

public void paintComponent(Graphics g) { 
    super.paintComponent(g); 
    setBackground(Color.white); 
    int w = getSize().width; 
    int h = getSize().height; 
    Graphics2D g2d = (Graphics2D) g; 
    FontRenderContext fontRendContext = g2d.getFontRenderContext(); 
    Font font = new Font("Verdana", 1, 72); 
    String st = new String(text1); 
    TextLayout text = new TextLayout(st, font, fontRendContext); 

    Shape shape = text.getOutline(null); 
    Rectangle rect = shape.getBounds(); 

    AffineTransform affineTransform = new AffineTransform(); 
    affineTransform = g2d.getTransform(); 
    affineTransform.translate(w/2 - (rect.width/2), h/2 
      + (rect.height/2)); 
    g2d.transform(affineTransform); 
    g2d.setColor(Color.black); 
    g2d.draw(shape); 
    g2d.setClip(shape); 
} 

的问题是我不知道如何来调整轮廓的厚度。 我试图在第一个字符串上显示另一个更大的字符串,但结果很糟糕(像素错误...)。

你有什么想法吗?

在此先感谢。

可以使用setStroke考虑看看。例如

g2d.setStroke(new BasicStroke(4));