For the image all I get is a broken image, is it possible to nest img tags inside a JLabel
它是能够显示在JLabel的文本图像(一个或多个)。由于的路径不正确,所以您正在破损图像。你需要用file:
或者用class.getResource("/your/path")
来代替你的路径。这是一个工作示例,只需插入有效的资源路径即可。
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MultipleImagesExample
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
JLabel label = new JLabel(
"<html>"
+ "<img src=\""
+ MultipleImagesExample.class.getResource("/resource/path/to/image1")
+ "\">"
+ "<img src=\""
+ MultipleImagesExample.class.getResource("/resource/path/to/image2")
+ "\">"
+ "The text</html>");
frame.add(label, BorderLayout.CENTER);
frame.setBounds(100, 100, 200, 100);
frame.setVisible(true);
}
}
对于java中更复杂的HTML,我推荐xhtmlrenderer。
不是它的问题很多,但我相信你的意思''
什么 – 2011-01-04 21:12:16