I had a previous post regarding rotating a JLabel and that involved creating a class that extends the BasicLabelUI class to do the rotation. JButton also has a class of its own called BasicButtonUI that you need to inherit in order to do rotation vertically.

To set the JButton to a certain angle, just set the parameter as either 90 or 270 in the VerticalButtonUI class. Kudos to the developer who created this class (I don’t know who).

Here is the code for the VerticalButtonUI class.

To rotate a JLabel‘s text vertically, you only need to use this class and pass it as a parameter to the JLabel‘s setUI() method. Kudos to the developer who created this class to make it easy for other developers to plug this class in and create a vertical JLabel in an instant.

To use this class, check the code below:

This is the code for the VerticalLabelUI class.

Related Posts Plugin for WordPress, Blogger...