简体   繁体   English

如何在JLabel中制作另一行

[英]How to make another line in JLabel

hello I know this was dumb question but may I ask how to make another line in JLabel ? 你好,我知道这是一个愚蠢的问题,但是我可以问一下如何在JLabel中做另一行吗? Or to make the label Doraemon print on the second line? 还是要在第二行上打印emon啦A梦标签? Thank you in advanced 谢谢高级

我的密码

您可以执行以下操作:

JLabel l = new JLabel("<html>pikachu<br>Doraemon </html>", SwingConstants.CENTER);

You need to use one of the Layout Managers, or if you set the layout manager to null by writing 您需要使用布局管理器之一,或者通过以下方式将布局管理器设置为null

fr.setLayout(null);

then you should set the bounds correctly 那么你应该正确设置界限

lbl.setBounds( , , , ,)   

and set the paramaters on how far from the top each label should be 并将参数设置为每个标签应该离顶部多远

the first paramater sets how far from the left and the second from the top. 第一个参数设置距左侧的距离,第二个距顶部的距离。 The last 2 set the size of the label. 最后2个设置标签的大小。

我认为您需要像这样更改代码fr.setLayout(new GridLayout(2,1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM