【发布时间】:2016-12-12 06:51:28
【问题描述】:
如何在没有 HTML 标记的情况下从 JLabel 中检索文本?
例如
自定义标签:
public CustomJLabel extends JLabel(){
private String text;
public CustomJLabel(String text) {
super("<html><div style='text-align: center;'>"+text+"</div></html>"),
this.text=text;
}
}
主要方法:
testCustomLbl = new CustomJLabel("Testing");
System.out.println(testCustomLbl.getText());
我得到的输出:
<html><div style='text-align: center;'>Testing</div></html>
期望的输出:
Testing
【问题讨论】:
-
请提供getText()方法的代码
-
这是默认的getText()方法,返回一个字符串,
标签: java html tags label jlabel