i have an extended JLabel class, called OrientationLabel, holding a single character. That character is '>' and inside my extended class is a function called flip which basically changes the character from '>' to '<'. anyway what i want to do is rotate the label in order for it to align with an edge.
Note: I also have an edge class which consists of two Point objects. inside that class is a function called center() which returns a computed center Point object in between the two points that form the edge. and also an angle() function that computes the angle that the edge makes.
i pass the angle and center point to my constructor of my orientation label and here is my resulting paintComponent function:
@Override
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D)g;
this.setLocation(Math.round(center.getX() - (getWidth()/2)), Math.round(center.getY() - (getHeight()/2)));
g2.rotate(-rotation, getWidth() / 2, getHeight() / 2);
super.paintComponent(g);
}
The problem is that as i rotate the label, sometimes it does not align exactly with the line. It points along the direction ok and the flip() function works perfectly but like i said sometimes you can tell its not perfectly aligned. Also i feel it sometimes comes out a little skewed.
I'm guessing this has something to do with the rotational center. If the width of the character is an odd number then the center will be a pixel rather than half a pixel?
Keep in mind i have been using java for a very long time in uni however we never really explored using the Graphics/Graphics2D classes therefore i would also appreciate some good resources where i can quickly learn these concepts/hierarchies a little better.
Rotating the label in 90 degrees intervals does not skew the label, it is when i have angles like 53 degrees or something. plus i am trying to keep the label aligned with my line or edge after the rotation has been performed. i do not believe this specific problem has been addressed here in these forums. Please at least help provide me with good and quick to learn resources for Graphics/Graphics2D or swing in general