How can I make image link work in JtextPane? - java

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());
}

Related

Image link not showing image

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.

How to Print in Vaadin

I have a VerticalLayout filled with components in Vaadin. PLease i will to print this layout exactly as it is to an A4 paper. Any Idea how to do this, Code Sample will be great.
Straight out of the Vaadin doc…
Printing the Browser Window
Vaadin does not have special support for launching the printing in browser, but you can easily use the JavaScript print() method that opens the print window of the browser.
Button print = new Button("Print This Page");
print.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// Print the current page
JavaScript.getCurrent().execute("print();");
}
});
The button in the above example would print the current page, including the button itself. You can hide such elements in CSS, as well as otherwise style the page for printing. Style definitions for printing are defined inside a #media print {} block in CSS.
There's no "built-in" API for printing in Vaadin.
You have to use the browser's native printing API.

gwt suggestbox doesn't hide on page scroll

I've created a suggest box and generated HTML page with huge text, so I can scroll.
1. Show suggest list
2. Scroll page
The popup box with suggestion list moves with scrolled page, but I want that it will neither hide when page scrolls nor move with page.
As I understand that suggest popup has absolute position. But is there some non css solution.
Answer to:
I've tried add scroll handler to Window, but I've found out that handle only event when I have and right of them moves, only in this case. If I have one scroll to scroll page like in case with large text - nothing invokes
When constructing a SuggestBox you can provide your own SuggestOracle, TextBox and SuggestionDisplay. DefaultSuggestionDisplay can be used to hide suggestion list. You can do it in Window.scrollHandler.
Here is the code:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
oracle.add("one");
oracle.add("two");
oracle.add("three");
TextBox box = new TextBox();
final DefaultSuggestionDisplay display = new DefaultSuggestionDisplay();
SuggestBox suggestBox = new SuggestBox(oracle, box, display);
Window.addWindowScrollHandler(new ScrollHandler() {
#Override
public void onWindowScroll(ScrollEvent event) {
display.hideSuggestions();
}
});
Note, that you need to use DefaultSuggestionDisplay - see documentation on deprecated hideSuggestionList method.
I hope that the example explains it all.
I've also checked that if you don't use own SuggestionDisplay it uses DefaultSuggestionDisplay anyway. So you can do it even simpler.
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
EDIT:
If not the whole window is scrolled but only content of some panel, you can add a ScrollHandler to the panel:
panel.addDomHandler(new ScrollHandler() {
#Override
public void onScroll(ScrollEvent event) {
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
}
}, ScrollEvent.getType());

Java ZK+Javascript JQuery Galleria IO FullScreenMode

i am using Galleria plugin for JavaScript i need show the image in full Screen modei have checked the APIand have a method.
.enterFullscreen( [callback] )
returns Galleria
This will set the gallery in fullscreen mode. It will temporary manipulate some document styles and blow up the gallery to cover the browser screen. Note that it will only fill the browser window, not the client screen (javascript can’t do that).
API
i am using ZK Framework responding to a button click using this code.
public void imageZoomer()
{
Clients.evalJavaScript("$('#galleria').data('galleria').enterFullscreen(function() {alert('full screen mode');})");
}
but nothing happens i have also try using
Clients.evalJavaScript("imageZoomer()");
and a javascript function like this
function imageZoomer()
{
alert('before');
$('#galleria').data('galleria').enterFullscreen(function(){alert('full screen mode');})
alert('after');
}
the above function is called but nothing happens but if a try this code on firebug console
$('#galleria').data('galleria').enterFullscreen(function(){alert('full screen mode');})
it works smoothly what i am doing wrong thanks a lot.
finally i could solved my issue using a xmhtml button in ZK and responding onClick event using JQuery i couldn't solve my issue using ZK button here is my code i hope i really helps somebody.
<div xmlns:h="xhtml">
<h:button onclick="$('#galleria').data('galleria').toggleFullscreen();">Full Screen. </h:button>
</div>
best regards..

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/

Categories

Resources