本文介绍了如何旋转Swing文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法旋转Swing文本,例如在JLabel中以0度到360度(或-180到180度)之间以1度的步长旋转?
Is there a way to rotate Swing text such as in a JLabel between 0 and 360 (or between -180 and 180) degrees in 1 degree steps?
推荐答案
是的。看看Graphics2D.rotate()。对于JLabel,我认为你可以覆盖paintComponent()方法来调用rotate(x),然后调用现有的paintComponent(),然后调用rotate(-x)。例如。
Yes. Look at Graphics2D.rotate(). For a JLabel, I think you could override the paintComponent() method to call rotate(x), then call the existing paintComponent(), then call rotate(-x). e.g.
protected void paintComponent(Graphics g) {
Graphics2D g2 = ( Graphics2D )g;
g2.rotate(theta);
super.paintComponent(g2);
g2.rotate(-theta);
}
我没试过这个。您可能需要添加偏移量,请参阅Graphics2D.rotate(double theta,double x,double y)
I haven't tried this. You might need to add an offset, see Graphics2D.rotate(double theta, double x, double y)
这篇关于如何旋转Swing文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!