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.
Related
I have a Wizard containing two wizard pages (org.eclipse.jface.wizard.WizardPage) and would like to set the focus for each page separately so that always the top input field of each page is focused.
Setting the focus in WizardPage.createControl(Composite), the first page focus is set correctly. The second page does not have a focus.
This is due to Wizard.createPageControls(Composite) which creates all the pages at the beginning.
Where would be the place to handle the focus after switched to the next wizard page?
Override the WizardPage setVisible method and set focus when the page becomes visible:
#Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
// TODO set focus
}
}
JFace wizards don't offer a designated hook to set the focus. However, as Greg already mentioned, the setVisible() method can be used to set the initial focus of a wizard page.
Usually, the focus of wizard pages should only be set when showing the page for the first time. If a user returns back to a page, the focus should remain where it was when the page was left.
Therefore, I usually guard the focus code so that it is only executed when the page is shown for the first time:
private boolean firstTimeShown = true;
#Override
public void setVisible( boolean visible ) {
super.setVisible( visible );
if( visible && firstTimeShown ) {
firstTimeShown = False;
control.setFocus();
}
}
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());
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..
I have two labels, two datepickers, and a submit button within a DockLayoutPanel. I'm trying to just get the button to show up in the center of the panel.
Here is the code I am trying to get just to get the button centered:
Button b = new Button("Submit", new ClickListener()
{
public void onClick(Widget sender)
{
getAwards(text.getText(),text2.getText());
}
});
b.setWidth("80px");
b.addStyleName("gwt-Button");
and within my css:
.gwt-Button{
margin-left:auto;
margin-right:auto;
}
What edits or method do I have to take to actually get this to work?
Edit: For extra information, this button is being added to a DockLayoutPanel
Try:
.gwt-Button{
position:absolute;
left:50%;
margin-left: -40px; /* Width Button /2 */
}
Try disabling the loading of whatever default GWT theme you are using (such as clean) in your gwt.xml file, it may be messing with things, since you're using the same class name.
Alternatively, just use a CSS class name other than "gwt-Button" here.
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());
}