Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I present text vertically in a JLabel ? (Java 1.6)

Tags:

java

jlabel

I'm looking to have text display vertically, first letter at the bottom, last letter at the top, within a JLabel. Is this possible?

like image 248
Clinton Avatar asked Sep 18 '08 13:09

Clinton


People also ask

How do you rotate a JLabel?

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().

How do I add text to a JLabel?

You can do that as follows, label. setText(label. getText() + "text u want to append");

How do you wrap text in JLabel in Netbeans?

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.


1 Answers

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);
like image 110
Bruno Avatar answered Oct 17 '22 10:10

Bruno