I tried rotating JLabel
text on based selected angles 30, 90 etc.I wrote CustomJLabel
class:
public CustomJLabel extends JLabel {
private int angle=360; //setter and getters
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Rectangle rectangle = g2d.getClipBounds();
g2d.rotate((getAngle() * java.lang.Math.PI) / 4, rectangle.getCenterX(), rectangle.getCenterY());
}
}
Main.java:
CustomJLabel cst=new CustomJLabel ();
cst.setAngle(value);
cst.repaint();
cst.setSize(getPrefferedsize());
When running above code. Its rotated the text correct based on angle. But its not correctly the rectangle shape. Please check the below images.
Horizontal (360)
Vertical (90)
Please observe Red Color Circles and the image was Vertical 90 degress and check the. Here is the missing top and bottom lines for JLabel
. Why is it missing?