java how to make a JLabel with vertical text? [duplicate]

非 Y 不嫁゛ 提交于 2019-12-05 18:16:03

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

You can create a method that will transform your text into an HTML code 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;
}

Afterwards, if you'll use this method in a setText method like this: someLabel.setText(transformStringToHtml(someString)); where someString = "Test" you will receive:

T
e
s
t

in your label.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!