user2997477
user2997477

Reputation: 11

How can I rotate a JPanel?

I am working on a chess game. I made my chess board using a JPanel.

This JPanel consists 64 JLabels representing the 8x8 chess blocks.

I want to rotate this JPanel so that the entire chess board can be rotated according to the player's choice.

Please suggest me a way to do this.

Upvotes: 0

Views: 5083

Answers (2)

Alex
Alex

Reputation: 1008

JPanel is meant to be static, if you want a fancy rotation movement, you should load an imagemap and code an algorithm to rotate all pixels (or going openGL with joGL library if that were the case) or, if you don't want to show any dynamic translation, be sure that all the objects representing the pieces, the squares and the table itself, have a dimension attribute associated to them, so you can force a repaint of the jpanel with the dimension attributes of all your figures rewritten depending of the angular movement (i.e. a tower at (7,1) should appear now on (8,7) if the table is moved 90 grades counterclockwise).

This question is very general, but had in mind that all objects represented will have to own a dimension attribute so you can repaint them at different positions when JPanel is reloaded.

Upvotes: 1

Martin
Martin

Reputation: 630

I think you can rotate the image but not the panel.

Please look at this answer https://stackoverflow.com/a/5271588/1446006

Upvotes: 0

Related Questions