Home > Net >  How can I add all the images from a website to a JEditorPane?
How can I add all the images from a website to a JEditorPane?

Time:10-25

I have a website, and a JEditorPane set up already. I'd like to iterate through all the images on the website, and add them to the editor pane, like so:

for (Image image : website.getImages()) {
    pane.add(image);
}

Obviously, this is not the real code, but I'd like something like that. Is this possible? I only want to add the images from the website, and no other non-essential HTML code/text.

CodePudding user response:

A JEditorPane can render HTML, and images can be loaded within that HTML. So the easiest way to display images is using HTML to embed them.

Here is an example that does exactly that. This HTML loads and displays two images. Put that HTML in an editor pane configured to display HTML, and the images should appear.

<html>
<body>
<img src='https://i.stack.imgur.com/gJmeJ.png'>
<img src='https://i.stack.imgur.com/xj49g.png'>
</body>
</html>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related