Java how to make JLabel with vertical text?

I need to make vertical JLabel

- a JLabel

that shows its text vertically - i searched google but i didn't find a good answer. how to do it?

enter image description here

+3


source to share


2 answers


You can use the VerticalLabelUI class generated by dev: http://tech.chitgoks.com/2009/11/13/rotate-jlabel-vertically/



+5


source


You can create a method that converts your text to code HTML

like this:

public static String transformStringToHtml(String strToTransform) {
    String ans = "<html>";
    String br = "<br>";
    String[] lettersArr = strToTransform.split("");
    for (String letter : lettersArr) {
        ans += letter + br;
    }
    ans += "</html>";
    return ans;
}

      

Then if you use this method in a method setText

like: someLabel.setText(transformStringToHtml(someString));

where someString = "Test"

you get:



T
e
s
t

      

in your label.

0


source







All Articles