Girando um JTextField verticalmente
Eu vi uma série de perguntas que perguntam como girar um JLabel ou imagem em um ângulo arbitrário. Tudo o que preciso fazer é girar meu campo de texto em 90 graus, mas não encontrei uma maneira mais fácil especificamente para esse ângulo. Eu pensei que copiei as respostas corretamente, mas meu campo de texto não está girando.
Aqui está um SSCCE do que estou fazendo:
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class VerticalRotationSSCCE {
private static class VerticalTextField extends JTextField {
private static final long serialVersionUID = 1L;
public VerticalTextField(String text) {
super(text);
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
int cx = getWidth() / 2;
int cy = getHeight() / 2;
g2.rotate(1/2 * Math.PI, cx, cy);
super.paintComponent(g2);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.getContentPane().add(new VerticalTextField("Foo"));
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
O que estou perdendo nas respostas sobre como girar componentes?