Rotate JButton's text
I want my JButton
to rotate its text (开发者_JS百科not the whole button) a bit when it's hovered. How do I do that?
It sounds like you'll need to do 2 things:
- Build a custom paint method that displays the desired effect.
- Add a mouse motion listener to the button to detect that the effect should be activated.
Good luck, I hope this helps!
What does "rotate the text a bit" mean? What is the purpose of this. As you rotate text the top and bottom will be clipped as you reach the edges of the button.
I think the basic code would be something like:
public void paintComponent(Graphics g)
{
if (mouseOver)
{
Graphics2D g2d = (Graphics2D)g;
g2d.rotate(...);
super.paintComponent(g2d);
g2d.rotate(...);
}
else
super.paintComponent(g);
}
Instead of rotating maybe a better solution is to shift the text up/down a couple of pixels, then you don't have to worry about truncation. The basic code should be the same but you would use the translate(...) method.
精彩评论