JEditorPane embedded images cannot be displayed - java

Good evening,
I've been trying to display html code in a JEditorPane with embedded images. The code for the image that I receive is the following:
<img title="1909-yamaha-nemesis2.jpg" alt="1909-yamaha-nemesis2.jpg" src="cid:ii_12d7652d11e8d9a6">
As you can imagine, I cannot display the image, any idea? I suspect it should be the CID codification.
Thank you in advance,

http://java-sl.com/tip_local_images.html
You can use the same approach and place your image in the local cache.

Related

Inserting image in JLabel using HTML in the text property

I want to display an image in a label. But using image icon property I cannot set the size of the image. So I am using HTML coding in the text property of JLabel to display image.
The image is not displaying so there must be some error. The alt text is being displayed. I tried the same coding in notepad and it worked. Please mention if there is any other way to display an image of a fixed size in label.
<html>
<body>
<img src="file://C:/Users/Lenovo/Desktop/Wallpapers/New folder/1mb.jpg" alt="Smiley face" height="142" width="142">
</body>
</html>
Is there a simple way to resize the image icon then please answer that also. I am making a project for my school so the codings should not be oh high level.
Thank you.

Gather text-data from html file

I'm making an app which will display quite a lot of information in text. I would love to be able to change this text without having to do any updates to the app itself and there-fore it would be great to just get the text from a simple HTMl-file from a server and display it in a textview. Is this possible?
TL;DR: Is there a way to display text from a remote HTML-file in a textview?
-Alexander
Your app can send a request to get your HTML page and then set the value of a TextView to be the content of the page as shown in this example: https://developer.android.com/training/volley/simple.html

Images are not showing in pdf created using velocity template

I create pdf using Velocity template, but i am not able to put images in pdf.
I am adding url into context object and accessing that object into eot.vm file, url is going proper but still images are not displaying in pdf.
Thanks & Regards,
Tushar
Make sure that URL you are passing is sending IMAGE as response not an full html page.
i was passing URL that was sending me a whole html page, so i was unable to see images.
But now its fixed.
Please visit below link:
https://answers.atlassian.com/questions/2907/how-to-access-image-generated-via-velocity-template-confluence

captcha image coming back a binary data? How to display this?

I am retrieving a captcha image from the Java based package "SimpleCaptcha"
On the front end I just put the following in my page and I get a captcha image:
<img src="stickyImg" />
I want to reload this captcha image onclick using javascript.
I tried:
$("#theclickhandler").click(function(){
$("#stickyImg").load('stickyImg', function(response){
$("#stickyImg").attr('src', response);
});
return false;
});
This gets the image but outputs something like this (greatly shortened obviously):
<img src="captcha image�PNG �ݚ��L�23U�݆�}$�J����Dy����IEND�B`� ">
That looks like raw, binary data to me. How do I get this to work?
The src attribute of an image tag specifies to the browser where the image to load is, not the content of the image. So you're stuffing the content of the image into the place where you want the location to be, and that's giving you garbage because it simply doesn't make sense.
So, to reload the image, you need to tell the browser that the address of the image has changed. It's not sufficient to simply rewrite the location in the image's src attribute to the same address -- that won't tell the browser to change anything. You can overcome this by stuffing some random data in the query string, say, the time of the request. Like #mikerobi suggests, you can just rewrite the src tag, here with the modification of putting a timestamp in the query string (which your servlet will almost surely ignore):
$('#stickyImg').attr('src', 'stickyImg?' + (new Date().getTime()));
You can't use that approach to load images, you need to set the image url attribute to the path of the image generator.
$('#stickImg').attr('src', 'path/to/image/generator');
I don't know how many browsers support it, but it's possible to base64 encode an image, prefix it with (depending on the image format) "data:image/png; base64,", and use that as a URI for the image.

Render html in Swing application

I have a swing application that sends commands to server and receives result in XML format. I need to transform this into HTML via XSLT and then display result HTML on the panel. The problem is that the only Swing component which is able to display HTML - JEditorPane - takes either URL or javax.swing.text.StyledDocument as a source.
Option with URL doesn't work for me because I have to save my html as a file on the file system first and I'd like to avoid this.
So I have a gap between in-memory result of XSL transformation and javax.swing.text.StyledDocument, which can be rendered by JEditorPane or JTextPane.
How to transform one to another? Or are there any other Swing solutions to display HTML from some in-memory source(DOM or String or whatever)?
Thank you in advance for help.
Is there a reason that JEditorPane.setText() does not work for you?
I use JEditorPane all the time and I've never pulled the displayed data from a file or URL. So it is possible. Just need to figure out why it's not working for you.
To be specific:
editor.setContentType( "text/html" );
editor.setText( "<html><body>Hello, world</body></html>" );
What about JeditorPane.setText() ?

Categories