Skip to main content

Java FX Container for web app

2 replies [Last post]
javiergodas
Offline
Joined: 2014-01-18
Points: 0

Hi, I am trying to develop a container in javaFX as a WevView to display a web app, in the NetBeans IDE
I am trying to display hola.html inside the container, which is in the same directory as the jar file, so theorically there wouldn't be any kind of problem on displaying it inside the container, but all I get is a blank page that does nothing.
Is there any javascript or html javaFX doesn't display correctly?
Perhaps because of the resolution of the window is smaller than the resolution of the html page, that it doesn't show it?
Is there any way to change Netbeans project execution so it doesn't create an temporary directory and places the jar there so the path would fit?
Is the WebView for online pages only and does not display local ones?
I am using Linux Mint last version, also java JRE last version

package contenedor;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class Contenedor extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
public void start(Stage primaryStage) throws Exception
{
primaryStage.setTitle("SADEI");

WebView browser = new WebView();
WebEngine engine = browser.getEngine();
String url = "hola.html";
engine.load(url);

StackPane sp = new StackPane();
sp.getChildren().add(browser);

Scene root = new Scene(sp);
primaryStage.setScene(root);
primaryStage.show();
}
}

thanks,
javier

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
javiergodas
Offline
Joined: 2014-01-18
Points: 0

anyone?

luiz.souza
Offline
Joined: 2012-06-03
Points: 0

your code seems to be ok. Just to be sure, try to use the absolute path's URL from a file, like this:

File f = new File("Path to file");
String URL = f.toURI.toURL.toString();

Engine.load(URL);

When the Engine don't find the page to open, it simply does nothing, which explain your blank screen.

You gotta google more about these issues, there are plenty of examples.