Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swing components : vertical text question

If I have a button like the one in this image :

http://www.freeimagehosting.net/image.php?4cd775814c.png

how could I make the text display itself vertically ? As in

j
B
u
t
t
o
n
1

I would like to know how to do the same thing for JLabel . I'm sure there has to be a better way than to create as many labels as there are characters in the string . Right ?

EDIT: how can I insert an image into my post ? The button for the image shows the image in the preview section , but when I actually post the data , I only get some text back , like the tags are getting messed up .

like image 939
Geo Avatar asked Dec 27 '25 14:12

Geo


2 Answers

I don't know if this is useful to you, but this sample shows how to make a vertical label. The difference is that it rotates all of the text (and/or the icon) instead of stacking the letters. I don't know how difficult it would be to modify it to do what you're asking.

The advantage of doing it this way is if your labels can change at runtime; generating big HTML strings might be a pain compared to a simple label.setUI(new VerticalLabelUI(true)); (and you don't have to worry about <> in the label text).

like image 119
Michael Myers Avatar answered Dec 31 '25 17:12

Michael Myers


You can use HTML for JButton or JLabel. So

button = new JButton("<html>J<br>b<br>u<br>t<br>t<br>o<br>n<br>1</html>");

should do the trick.

like image 39
asalamon74 Avatar answered Dec 31 '25 18:12

asalamon74



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!