JLabel的Newline [英] Newline in JLabel

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

问题描述

如何在 JLabel 中显示换行符?

例如,如果我想:


Hello World!

blahblahblah




  JLabel l = new JLabel(Hello World!\\\
blahblahblah, SwingConstants.CENTER);

这是显示的内容:


Hello World!blahblahblah

如果这是一个愚蠢的问题,我只是在学习一些Swing基本知识...

解决方案

< html>< / html> code>,然后打破< br /> 的界限。 c $ c> JLabel l = new JLabel(< html> Hello World!<> blahblahblah< / html>,SwingConstants.CENTER);


How can I display a newline in JLabel?

For example, if I wanted:

Hello World!
blahblahblah

This is what I have right now:

JLabel l = new JLabel("Hello World!\nblahblahblah", SwingConstants.CENTER);

This is what is displayed:

Hello World!blahblahblah

Forgive me if this is a dumb question, I'm just learning some Swing basics...

解决方案

Surround the string with <html></html> and break the lines with <br/>.

JLabel l = new JLabel("<html>Hello World!<br/>blahblahblah</html>", SwingConstants.CENTER);

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

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