Image link not showing image - java

I am using Java and Vaadin to create a simple view where an image is displayed. I have a single Image element containing a source link. Here is my code.
#Route(value = "")
public class MainView extends VerticalLayout {
public MainView() {
add(new Image("https://media.reaperscans.com/file/4SRBHm/comics/14659ab2-5650-4aaf-a5bb-9ad5a9828662/chapters/3aff6399-5ff4-46d1-b502-88788510d962/000.jpg", ""));
}
}
This compiles to a HTML in the browser containing an image element:
<img src="https://media.reaperscans.com/file/4SRBHm/comics/14659ab2-5650-4aaf-a5bb-9ad5a9828662/chapters/3aff6399-5ff4-46d1-b502-88788510d962/000.jpg">
When I open this image in new tab I can see the image correctly, but when I see it in my app there is only:
EDIT:
I can open the image using the link in Google Chrome.

If you open the image on Chrome you will notice the website doesn't allow hotlinking. That's why it doesn't load. Try using a different image (from Wikipedia, for example) and it should work well.
new Image("https://upload.wikimedia.org/wikipedia/commons/8/8e/Vaadin-flow-bakery.png","vaadin");
I recommend using the alt attribute as well, instead of leaving it empty as you had in your original question.

Related

How to get the data from one browser window to other window in gwt?

First of all i would like to say that i have gone through all the posts which are similar to my query but i have some different requirement.
In our project we are using gwt to develop the modules, in one of our module, we have "Edit" button which opens a new browser window which includes 'CKEditor'.
We are modifying the data in ckeditor comes(by url) from gwt widget .
The Window opens by using following code snippet(JSNI) in my gwt widget:
private static native BodyElement getBodyElement(String url) /*-{
var win = window.open("url", "win", "width=940,height=400,status=1,resizeable=1,scrollbars=1"); // a window object
return win.document.body;
}-*/;
The newly opened window have the html form which is with ckeditor.
So here i am closing new window once my form has been submitted but i want the edited text to be displayed in old window.
How can i achieve this requirement?
If you can use HTML5, it should be quite easy. Use Messaging.
Take a look here:
Cross-document messaging
With the reference of the newly opened window, yu can establish a communication between both windows.

How can I make image link work in JtextPane?

I want to give a image link on my pc to a row on jtextpane.
I give "text/html" ttype to jtextpane
jTextPane1.setContentType("text/html");
and I wrote this code for give image:
html text:
<img src= file:/"+myimageplace+" alt=\"Click to Open Image\" width=\"30\" height=\"30\">
this is working for showing image.
But I want to give that image to go to image like this :
\"<img src= file:/"+mytext+" alt=\"Click to Open Image\" width=\"30\" height=\"30\">
But this isnt working?
How can I do that?
Thanks.
You need to have an event/link handler related to link clicks for this to work.
Even though your rendering HTML, without a specific link handler to handle clicks it will not open the window.
I am quoting from here: Hyperlink in JEditorPane
Add the link handler
By default clicking the links won't do anything; you need a HyperlinkListener to deal with them:
editor.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
// Do something with e.getURL() here
}
}
});
How you launch the browser to handle e.getURL() is up to you. One way if you're using Java 6 and a supported platform is to use the Desktop class:
if(Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(e.getURL().toURI());
}

Liferay - Image Gallery

Hello and thanks for taking the time to answer my question.
I have a custom portlet with a typical file upload html element. However, I was told that the user should be able to select already uploaded images and not upload new images. At the moment I am loading a web content display portlet on a random page, click on image icon in the rich text editor and copy the link in the javascript of my portlet, which opens the image gallery in a pop-up, in order to access the image gallery. However, this is not a plausible solution for production and I was wondering how I can load the image gallery from a custom portet. I need to be able to see the image gallery open in a pop-up with a user clicks Select an Image button.
Thanks in advance!
This code is enough to do this:
List<IGFolder> listIGFolders = null;
if(selectedFolderId!=0){
listIGFolders=IGFolderLocalServiceUtil.getFolders(groupId, selectedFolderId);
} else{
listIGFolders = IGFolderLocalServiceUtil.getFolders(groupId);
}
List<IGImage> igImages=IGImageLocalServiceUtil.getImages(groupId, selectedFolderId);

Direct link to lightbox and automatically open

I need to be able to directly link to images within a lightbox (currently using Lightbox2) from an external website. Basically I want to post a link to one of my images on say, Twitter, and have the link go to my website, open a lightbox, and display the image. I also need to be able to see the image link URL in the address bar while viewing the image in a lightbox. I found this: http://www.huddletogether.com/forum/comments.php?DiscussionID=1407 but it's for an old version of lightbox and for the life of me I couldn't get it work.
Here's a working example:
http://www.rudirakete.de/rudirakete/main#2008-10-5-1526107735
Why not use jQuery dialog().
var p = '<img src="http://www.geekologie.com/2007/12/07/future-car-1.jpg" />';
$('a').click(function() {
$(p).dialog({
minWidth: 500,
buttons: {
OK: function() {
$(this).dialog("destroy");
}
}
})
})
Check working example at http://jsfiddle.net/msKZt/3/

How to render image within an html dynamically?

I am having some html content with images(html+images) embedded inside it on my local drive. When i open it by double clicking on browser directly, i am able to see the content with embedded images in it.
Now i have to render this content on web browser using java apis.I am able to render html content without any issue but while rendering , image is not getting rendered , instead alt text is getting rendered on browser.
I got to know that i can not set two mime types in java code to render image as well as text on same page.I want to know how can i render html content with image inside it so that it can be rendered.
Regards.
Code added:
public void readFile() throws FileNotFoundException{
String lsFilePath = "D:\\alf3.3\\deployment\\target\\";
//String lsFilename = "/WEB-INF/message.properties";
String lsFilename = "spcontent2.html";
File loNewFile = new File(lsFilePath + lsFilename);
FileInputStream loFileInputStream = new FileInputStream(loNewFile);
FileOutputStream loFilOutputStream = new FileOutputStream(loNewFile);
}
It is fine till now but i need to know how can i render an image that is referred to in file mentioned.
For embedding an Image into html source page by adding content id into image source. This is usually practised while sending HTML emails with embedded images
Please refer following document for more info.
http://www.faqs.org/rfcs/rfc2111.html

Categories

Resources