JLabel在java_java – JLabel在另一个JLabel之上

简短的回答是肯定的,因为JLabel是Container,所以它可以接受Component(JLabel是Component的子类)通过使用add方法添加到JLabel中:

JLabel outsideLabel = new JLabel("Hello");

JLabel insideLabel = new JLabel("World");

outsideLabel.add(insideLabel);

在上面的代码中,insideLabel被添加到outsideLabel中.

但是,在视觉上,显示带有“Hello”文本的标签,因此无法真正看到标签中包含的标签.

因此,问题在于通过在另一个标签上添加标签来实现真正想要实现的目标.

编辑:

来自评论:

well, what i wanted to do was first,

read a certain fraction from a file,

then display that fraction in a

jlabel. what i thought of was to

divide the fraction into 3 parts, then

use a label for each of the three.

then second, i want to be able to drag

the fraction, so i thought i could use

another jlabel, and place the 3’mini

jlabels’ over the big jlabel. i don’t

know if this will work though..:|

听起来应该研究如何在Java中使用布局管理器.

听起来像GridLayout可能是完成任务的一种选择.

JPanel p = new JPanel(new GridLayout(0, 1));

p.add(new JLabel("One"));

p.add(new JLabel("Two"));

p.add(new JLabel("Three"));

在上面的示例中,JPanel使用GridLayout作为布局管理器,并被告知要生成一行JLabel.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值