JLabel可以有img标签吗? [英] can JLabel have img tags

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

问题描述

我正在尝试显示一个JLabel,其中包含几行文本和一个图像,如下所示:

I am trying to display a JLabel which has a few lines of text and an image as follows:

String html = "<html> hello </br> <img src = \"/absolute/path/here\" height = \"30\"  width =\"40\"/> </html>";
JLabel l = new JLabel(html);

对于我得到的图像来说,是一张破碎的图像,是否可以在JLabel中嵌套img标签?

For the image all I get is a broken image, is it possible to nest img tags inside a JLabel?

我想向JLabel添加多个图像,所以我认为在这里不使用ImageIcon.

I want to add multiple images to the JLabel so I don't think the use of an ImageIcon will do here.

谢谢

推荐答案

而不是尝试在单个JLabel上包含多个图像,为什么不简单地拥有多个JLabel,每个JLabel包含一个图像(如uthark所述),然后将所有标签分组一起在一个JPanel上.这样应该可以让您以最小的附加复杂度获得所需的效果.

Rather then try to have multiple images on a single JLabel why not simply have many JLabels, each with one image (as uthark described) and then group all the labels together on a single JPanel. That should give you the effect you are looking for with only minimal additional complexity.

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

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