本文介绍了Java2D:增加线宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想增加Line2D的宽度。我找不到任何方法来做到这一点。我需要为此实际制作一个小矩形吗?
解决方案
您应该使用 setStroke
来设置
Graphics2D
对象的笔画。
。
I want to increase the Line2D width. I could not find any method to do that. Do I need to actually make a small rectangle for this purpose?
解决方案 You should use setStroke
to set a stroke of the Graphics2D
object.
The example at http://www.java2s.com gives you some code examples.
The following code produces the image below:
import java.awt.*;
import java.awt.geom.Line2D;
import javax.swing.*;
public class FrameTest {
public static void main(String[] args) {
JFrame jf = new JFrame("Demo");
Container cp = jf.getContentPane();
cp.add(new JComponent() {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(10));
g2.draw(new Line2D.Float(30, 20, 80, 90));
}
});
jf.setSize(300, 200);
jf.setVisible(true);
}
}
(Note that the setStroke
method is not available in the Graphics
object. You have to cast it to a Graphics2D
object.)
This post has been rewritten as an article here.
这篇关于Java2D:增加线宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!