Boo*_*ean 2 java graphics java-2d
我正在使用 Java2d 开发应用程序。我注意到的奇怪的事情是,原点在左上角,正 x 向右移动,正 y 向下增加。
有没有办法移动原点左下角?
谢谢你。
您将需要进行缩放和翻译。
在你的paintComponent方法中,你可以这样做:
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.translate(0, -height);
g2d.scale(1.0, -1.0);
//draw your component with the new coordinates
//you may want to reset the transforms at the end to prevent
//other controls from making incorrect assumptions
g2d.scale(1.0, -1.0);
g2d.translate(0, height);
}
Run Code Online (Sandbox Code Playgroud)
我的 Swing 有点生锈,但这应该可以完成任务。