如何旋转Swing文本?

jac*_*nad 7 java swing jlabel

有没有办法旋转Swing文本,例如在JLabel中以0度到360度(或-180到180度)之间以1度的步长旋转?

use*_*300 9

是.看看Graphics2D.rotate().对于JLabel,我认为你可以覆盖paintComponent()方法来调用rotate(x),然后调用现有的paintComponent(),然后调用rotate(-x).例如

protected void paintComponent(Graphics g) {
   Graphics2D g2 = ( Graphics2D )g;
   g2.rotate(theta);
   super.paintComponent(g2);
   g2.rotate(-theta);
}
Run Code Online (Sandbox Code Playgroud)

我没试过这个.您可能需要添加偏移量,请参阅Graphics2D.rotate(double theta,double x,double y)