I'm looking to have text display vertically, first letter at the bottom, last letter at the top, within a JLabel. Is this possible?
By default, JLabel can display a text in the horizontal position and we can rotate a JLabel text by implementing the rotate() method of Graphics2D class inside the paintComponent().
You can do that as follows, label. setText(label. getText() + "text u want to append");
As per @darren's answer, you simply need to wrap the string with <html> and </html> tags: myLabel. setText("<html>"+ myString +"</html>"); You do not need to hard-code any break tags.
You can also use the SwingX API
Bottom to top :
JXLabel label = new JXLabel("MY TEXT");
label.setTextRotation(3 * Math.PI / 2);
Top to bottom :
JXLabel label = new JXLabel("MY TEXT");
label.setTextRotation(Math.PI / 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With