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

与世无争的帅哥 提交于 2019-12-07 07:14:44

问题


i need to make a vertical JLabel- a JLabel which shows it's text vertically- i searched google but i didn't find a good answer. how to do that?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/14777926/java-how-to-make-a-jlabel-with-vertical-text

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