Hey guys,

I've seen very limited examples out there about this unsupported function, however I am sure there must be a quick method to get this done with the Affine Transform ?

Any ideas appreciated.

Cleo

Recommended Answers

All 4 Replies

If you have the image, and are drawing it in a paintComponent method, then you can cast the Graphics g parameter to Graphics2D and use its rotate method. (which is an easier cover method for a rotational AffineTransform)

Thanks for your advice :)

Currently breaking this down, it works great but shorted is always better.

private JLabel lblRover = new JLabel(imageIcon) {
	protected void paintComponent(Graphics g) {
	Graphics2D g2 = (Graphics2D)g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
							RenderingHints.VALUE_ANTIALIAS_ON);
	AffineTransform aT = g2.getTransform();
	Shape oldshape = g2.getClip();
	double x = getWidth()/2.0;
	double y = getHeight()/2.0;
	aT.rotate(Math.toRadians(angle), x, y);
	g2.setTransform(aT);
	g2.setClip(oldshape);
	super.paintComponent(g);
    }
};

http://www.java-forums.org/awt-swing/24770-jlabel-rotation-property.html

Shorter is not always better - easier to understand is better. If you have ever had to fix or update someone else's code you would agree. Breaking it down to easy steps is a good thing; the compiler is very good at optimising simple code. Your code is great, don't change it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.