Rotate JButton Text

I want my JButton to rotate its text a bit (not the whole button) when it crashes. How to do it?

+4
source share
2 answers

It looks like you need to do 2 things:

  • Create your own drawing method that displays the desired effect.
  • Add a mouse button to move the mouse to the button to find that the effect needs to be activated.

Good luck, hope this helps!

+2
source

What does β€œrotate text a bit” mean? What is the purpose of this. When you rotate the text, the top and bottom will be trimmed as you approach the edges of the button.

I think the base code would be something like this:

 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, the best solution is perhaps to shift the text up / down a couple of pixels, then you do not need to worry about truncation. The main code should be the same, but you would use the translate (...) method.

+2
source

Source: https://habr.com/ru/post/1334177/


All Articles