JavaFX Web View - javafx-webview

I want to code a small web browser using JavaFX Web View. Here's my current code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebViewExample extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX WebView Example");
WebView webView = new WebView();
webView.getEngine().load("http://google.com");
VBox vBox = new VBox(webView);
Scene scene = new Scene(vBox, 960, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
}
When I want to compile it using
javac -p /Users/xamsoftware/javafx-sdk-11.0.2/lib --add-modules=javafx.controls WebViewExample.java
It says
WebViewExample.java:4: error: package javafx.scene.web is not visible
import javafx.scene.web.WebView;
^
(package javafx.scene.web is declared in module javafx.web, which is not in the module graph)
1 error
Is there anybody that can help me?

So responding to one comment, you basically have to change --add-modules=javafx.controls to --add-modules=javafx.web.

Related

MapContainer show only on click/touch

I am trying to use naive map.
I have places a MapContainer insider a Form Component but the From shows blank without the map inside it, on the simulator. When I click on the viewport the map shows as long as the mouse button remains down. When I release it disappear again.
Is it a real problem or is it a misfunction of the simulator? If it is a real problem what am I doing wrong?
below is the class I am using:
package com.mainsys.zappeion;
import com.codename1.googlemaps.MapContainer;
import com.codename1.maps.Coord;
import com.codename1.ui.Form;
import com.codename1.ui.layouts.BorderLayout;
/**
*
* #author Christoforos
*/
public class ZappeionMap extends com.codename1.ui.Form {
private Form current;
public ZappeionMap() {
super("Ζάππειον", new BorderLayout());
}
#Override
public void show() {
if(current != null){
current.show();
return;
}
final MapContainer cnt = new MapContainer();
this.addComponent(BorderLayout.CENTER, cnt);
cnt.setCameraPosition(new Coord(41.889, -87.622));
super.show();
}
}
/********** Implementing Shai's answer ******************/
I changed my code to what Shai suggested show my class now is:
package com.mainsys.zappeion;
import com.codename1.googlemaps.MapContainer;
import com.codename1.location.Location;
import com.codename1.location.LocationManager;
import com.codename1.maps.Coord;
import com.codename1.ui.BrowserComponent;
import com.codename1.ui.FontImage;
import com.codename1.ui.Form;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.plaf.Style;
/**
*
* #author Christoforos
*/
public class ZappeionMap extends com.codename1.ui.Form {
private Form current;
private static final String HTML_API_KEY = "AIzaSyDHlFJK561bQVs0AyBm1M5xWS_YCHNuPfc";
public ZappeionMap() {
super("Ζάππειον", new BorderLayout());
final MapContainer cnt = new MapContainer( HTML_API_KEY );
this.addComponent(BorderLayout.CENTER, cnt);
cnt.setCameraPosition(new Coord(41.889, -87.622));
}
}
It still having the same problem. The screen is blank. The map only shown when I click on the screen.
I also noticed something else. On the debuger I get the message:
WARNING: Apple will no longer accept http URL connections from applications you tried to connect to http://tile.openstreetmap.org/4/2/9.png to learn more check out https://www.codenameone.com/blog/ios-http-urls.html
Why is it trying to connect to http://tile.openstreetmao.org. It is supposed to work with google maps not with openstreet maps.
One more information, maybe it is worh something. I test it on real device. The screen is still blink but when I touch the screen it does not show anythink, in contrast with the simulater that when I click on the screen the map appears.
I am using netbeans 8.2 on centos 7
Any help is appreciated.
Thank you Christoforos.
Why are you overriding the show method of form and don't construct the UI n the constructor?
It looks like you copied some code from the lifecycle class and mixed it with a form subclass e.g. the current variable.
This is closer to correct:
public class ZappeionMap extends com.codename1.ui.Form {
private Form current;
public ZappeionMap() {
super("Ζάππειον", new BorderLayout());
final MapContainer cnt = new MapContainer();
this.addComponent(BorderLayout.CENTER, cnt);
cnt.setCameraPosition(new Coord(41.889, -87.622));
}
}

Automating responsive design using Selenium Webdriver

Is it possible to automate responsive design testing using Selenium Webdriver? Can it be done with chrome options or a library of some sort?
Try the following sample of Java Code with JUnit:-
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ResponsiveWebTest {
public WebDriver driver;
public List<Dimension> screenDimensionsList;
#Before
public void beforeTestMethod(){
// create list of dimensions for various screen sizes
screenDimensionsList = new ArrayList<Dimension>();
screenDimensionsList.add(new Dimension(1600,800));
screenDimensionsList.add(new Dimension(1200,800));
screenDimensionsList.add(new Dimension(992,800));
screenDimensionsList.add(new Dimension(768,800));
screenDimensionsList.add(new Dimension(480,800));
screenDimensionsList.add(new Dimension(360,800));
// initialize the driver for browser
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://nandal.in");
}
#Test
public void testVariousScreenSizes(){
for(Dimension d: screenDimensionsList){
driver.manage().window().setSize(d);
// run some test cases for this screen size
// some test case steps
try{
Thread.sleep(2000);
}catch(Exception e){
e.printStackTrace();
}
}
}
}
This will open chrome browser with given url, and then resizes the browser according to the dimensions list to test the responsive behavior of the webpage, You can add your test logic there.

Codenameone - TextField & Keyboard

I have problem with my TextField for getting user's input. I followed examples available (developer guide, stackoverflow etc etc), but somehow the keyboard doesn't appear. Attached is the code ( I deleted the rest of my codes for t'shooting purposes) & the screenshot.
Need help on how can I make the virtual keyboard appear.
TQ in advance.
import com.codename1.ui.Form;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.ui.Toolbar;
import com.codename1.io.Log;
import com.codename1.ui.TextField;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
/**
* This file was generated by Codename One for the purpose
* of building native mobile applications using Java.
*/
public class celebriesta {
private Form current;
private Resources theme;
private Form home, allEvent, specEvent, picEvent;
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
}
public void start() {
if (current != null) {
current.show();
return;
}
home = new Form("Home", BoxLayout.y());
home.setScrollableY(true);
TextField txt = new TextField();
txt.setFocusable(true);
txt.setConstraint(TextField.NUMERIC);
txt.startEditingAsync();
home.addComponent(txt);
home.show();
}
public void stop() {
current = getCurrentForm();
}
public void destroy() {
}
}
The keyboard doesn't appear in the simulator. Just use your computers keyboard to type into the text field.
When running on the device the native OS virtual keyboard will appear as expected.

BrowserComponent doesn't work on CodenameOne 3.7.2?

the following code doesn't work in the Simulator (on NetBeans 8.2 + CodenameOne 3.7.2 + Skin Iphone3gs) and doesn't work in my Android 4.1.2 device. It blocks the Simulator and it shows a blank screen on the real device (with a blinking "Loading..."). What's the problem? Thank you
import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.BrowserComponent;
import com.codename1.ui.Toolbar;
import com.codename1.ui.layouts.BorderLayout;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
/**
* This file was generated by Codename One for the purpose
* of building native mobile applications using Java.
*/
public class Gmail {
private Form current;
private Resources theme;
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
}
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Form title Example", new BorderLayout());
BrowserComponent browser = new BrowserComponent();
browser.setURL("https://students.uninettunouniversity.net/");
hi.add(BorderLayout.CENTER, browser);
}
public void stop() {
current = getCurrentForm();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
}
You deleted the hi.show() line at the end

where is the underscore in my CheckBox?

The shortest possible program to show my problem:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestCheckBox extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage stage) {
Scene scene = new Scene(new StackPane());
final VBox vbox = new VBox();
vbox.getChildren().addAll(new Label("ABC_DEF"), new CheckBox("ABC_DEF"));
((StackPane) scene.getRoot()).getChildren().add(vbox);
stage.setScene(scene);
stage.show();
}
}
leads to:
In SceneBuilder by comparison it´s displayed normally, but not in my application. I am running Java 1.8.0-b129
Any hint?
You probably want to setMnemonicParsing to false on the CheckBox.
MnemonicParsing property to enable/disable text parsing. If this is set to true, then the Label text will be parsed to see if it contains the mnemonic parsing character '_'. When a mnemonic is detected the key combination will be determined based on the succeeding character, and the mnemonic added.
The default value for Labeled is false, but it is enabled by default on some Controls.

Resources