0

is there an easy way to dell htmldocument (inside a JTextPane) to not load images from the web? i cant think of anything smarter then to simply remove the tags or similar. and cant seem to find any "build in" functionality for it.

1 Answer 1

1

this is the best i came up with:

String removeImageTags(String content)
{
    Pattern imageRegexp = Pattern.compile("<img.*?src=['\"]{1}([^\"']*)['\"]{1}.*?>");
    Matcher m = imageRegexp.matcher(content);
    if (m.find())
    {
        content = m.replaceFirst(m.group(1));
    }
    else
    {
        return content;
    }
    return removeImageTags(content);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.