Tag: stroke

为什么Graphics2D.setStoke()不适用于Graphics2D.drawString?

我希望字符串具有不同的宽度,以便我设置Graphics2D的笔划,代码在这里: import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class StrokeTest { public static void main(String[] args) { StrokeTest test = new StrokeTest(); test.createUI(); } public void createUI(){ JFrame frame = new JFrame(); frame.add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } @SuppressWarnings(“serial”) class MainPanel extends JPanel{ public MainPanel(){ setPreferredSize(new Dimension(400, […]

AffineTransform没有改变中风?

当使用带有两个不同参数的Graphics2D scale()函数(在x和y方向上按不同比例缩放)时,稍后在此Graphics2D对象上绘制的所有内容也会缩放。 这具有奇怪的效果,即在一个方向上绘制的线比在另一个方向上绘制的线更粗。 以下程序产生此效果,它显示此窗口: public class StrokeExample extends JPanel { public void paintComponent(Graphics context) { super.paintComponent(context); Graphics2D g = (Graphics2D)context.create(); g.setStroke(new BasicStroke(0.2f)); int height = getHeight(); int width = getWidth(); g.scale(width/7.0, height/4.0); g.setColor(Color.BLACK); g.draw(new Rectangle( 2, 1, 4, 2)); } public static void main(String[] params) { EventQueue.invokeLater(new Runnable(){public void run() { StrokeExample example = new […]