I have an application which consists of a JPanel
, in that Panel I can add components of type JLabel
which contains a text. I need that those jlabel
can be rotated when the following button is pressed:
I have tried the following method to change its rotation but I can not get the same label
repaint.
label = new JLabel("prueba") {
protected void paintComponent(Graphics grafico) {
Graphics2D graficoNuevo = (Graphics2D) grafico;
AffineTransform at = graficoNuevo.getTransform();
double X = getWidth() / 2.0;
double Y = getHeight() / 2.0;
at.rotate(Math.toRadians(90), X, Y);
graficoNuevo.setTransform(at);
super.paintComponent(graficoNuevo);
}
};
This code works to create a new label
but what I really need is that the label
previously created changes its rotation of the text it contains.