java java如何制作带有竖排文本的JLabel?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14777926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java how to make a JLabel with vertical text?
提问by Soheil
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?
我需要做一个垂直JLabel
-一个垂直JLabel
显示它的文本 - 我搜索了谷歌,但我没有找到一个好的答案。怎么做?
回答by eXa
You could use the class VerticalLabelUI created by a dev: http://tech.chitgoks.com/2009/11/13/rotate-jlabel-vertically/
您可以使用由开发人员创建的 VerticalLabelUI 类:http: //tech.chitgoks.com/2009/11/13/rotate-jlabel-vertically/
回答by Michael
You can create a method that will transform your text into an HTML
code like this:
您可以创建一个方法,将您的文本转换为这样的HTML
代码:
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:
之后,如果你在使用此方法setText
是这样的方法:someLabel.setText(transformStringToHtml(someString));
在那里someString = "Test"
,你将得到:
T
e
s
t
in your label.
在你的标签中。