JLabel新行无效 [英] JLabel new line doesn't work

查看:63
本文介绍了JLabel新行无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JLabelsetText()方法中,我的String遇到了一些意外的问题.

I've encountered some unexpected problem with my String in the setText() method of JLabel.

无论我做什么,断言变量时都无法设置新行.

No matter what I do, it just can't get it to set a new line when asserting variables.

到目前为止我已经尝试过的

what i've tried so far

Jabel l = new JLabel();
String string = new String();
string = var1+"\n"+var2;
string = var1+"\r\n"+var2;
string = var1+"<html><br/></html>"+var2;

l.setText(string);

推荐答案

您可以按照

You can use HTML within the JLabel as described in the online tutorial, and you almost got it right; the text you want to wrap has to be enclosed within the HTML tags like:

string = "<html>" + var1 + "<br/>" + var2 + "</html>";

尽管最好使用StringBuilder实际构建字符串.

although it might be better to use StringBuilder to actually build the string.

这篇关于JLabel新行无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆