我正在使用 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);
}
我的 Swing 有点生疏,但这应该可以完成任务。
关于Java2d : Translate the axes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2831213/