简体   繁体   English

如何将多个 jlabels 添加到按钮?

[英]How do I add multiple jlabels to a button?

So what I tried to do is create multiple JLabels, each corresponding to different data (name, attck_value, health_power, etc.), and add them separately to the already created button.所以我尝试做的是创建多个JLabel,每个对应不同的数据(name、attck_value、health_power等),并将它们分别添加到已经创建的按钮中。 However, I ended up getting the button with all the data overlapping one another.但是,我最终得到了所有数据相互重叠的按钮。 So what should I do?所以我该怎么做? How do I add multiple JLabels without them getting overlapped?如何添加多个 JLabel 而不会重叠?

I'm taking a guess here, but did you know you can add html to a JButton to create multiple line names.我在这里猜测,但您知道您可以将html添加到JButton以创建多个行名。 And you can change the text at any time while the GUI is in operation so the JButton can change its meaning.您可以在 GUI 运行时随时更改文本,以便 JButton 可以更改其含义。

JButton b = new JButton("<html>this<br>is<br>a<br><test></html>");

在此处输入图像描述

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

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