gpt4 book ai didi

java - JLabel 可以有 img 标签吗

转载 作者:太空狗 更新时间:2023-10-29 15:27:50 25 4
gpt4 key购买 nike

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

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

对于我得到的所有图像都是损坏的图像,是否可以在 JLabel 中嵌套 img 标签?

编辑:我想向 JLabel 添加多个图像,所以我认为在这里不适合使用 ImageIcon。

谢谢

最佳答案

File f = new File("C:\image.jpg"); 
jLabel1.setText("<html><img src=\"file:"+f.toString()+"\">");

这对我有用。它很简单,可以放置任意数量的图像,而不仅仅是一个图像图标。如果没有引号,它将无法正常工作。

关于java - JLabel 可以有 img 标签吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2484488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com