I have software that I am working on that uses JavaFx MediaPlayers and MediaViews to create a UI. For this to work the way we want we are reusing the MediaPlayers (after keeping them stored in a static class's hashMap) and then we place the MediaPlayer in new MediaViews when needed. When the MediaView is done we set it to null and move on, but this has lead to a memory leak where the number of players will stay constant but the mediaViews will increase. I made a minimal working version of this code so you can see the memory go up and up without collecting any mediaViews. It seems like the getOnError or the Error property from the MediaPlayer is holding onto an old reference of the MediaView. I would like to remove this, but it seems like you have to dispose of a mediaPlayer if you want to clean up all of it's memory, but I would like to save the Player and delete the View.
Here is some code that recreates the issue. Just hit the stop button a few times which will remove the old mediaView and add a new one, but none ever get cleaned up.
package JavaFx;
import java.io.File;
import java.net.URL;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayer.Status;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
public class FxMediaExample1 extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
public MediaView mediaView;
public Scene scene;
public VBox root;
#Override
public void start(Stage stage)
{
// Locate the media content in the CLASSPATH
// Create a Media
File file = new File("file:///C:/Users/Samuel%20Johnston/Downloads/cf86c6a4-271f-4dcb-bb11-fc30f5eb6b45_web.mp4");
if (file.exists()) {
System.out.println("Boobs");
} else {
System.out.println("poop");
}
Media media = new Media("file:///C:/Users/Samuel%20Johnston/Downloads/cf86c6a4-271f-4dcb-bb11-fc30f5eb6b45_web.mp4");
media.setOnError(() -> {
System.out.println("WHAT THE WHAT, " + media.getError().toString());
System.out.println("WHAT THE WHAT, " + media.getError().getMessage());
System.out.println("WHAT THE WHAT, " + media.getError().getStackTrace().toString());
System.out.println("WHAT THE WHAT, " + media.getError().getLocalizedMessage());
});
// Create a Media Player
final MediaPlayer player = new MediaPlayer(media);
player.setOnError(() -> {
System.out.println("WHY THE WHY, " + player.getError().toString());
System.out.println("WHY THE WHY, " + player.getError().getMessage());
System.out.println("WHY THE WHY, " + player.getError().getStackTrace().toString());
System.out.println("WHY THE WHY, " + player.getError().getLocalizedMessage());
});
// Automatically begin the playback
player.setAutoPlay(true);
// Create a 400X300 MediaView
mediaView = new MediaView(player);
mediaView.setFitWidth(700);
mediaView.setFitHeight(700);
mediaView.setSmooth(true);
// Create the Buttons
Button playButton = new Button("Play");
Button stopButton = new Button("Stop");
// Create the Event Handlers for the Button
playButton.setOnAction(new EventHandler <ActionEvent>()
{
public void handle(ActionEvent event)
{
if (player.getStatus() == Status.PLAYING)
{
player.stop();
player.play();
}
else
{
player.play();
}
}
});
stopButton.setOnAction(new EventHandler <ActionEvent>()
{
public void handle(ActionEvent event)
{
player.stop();
root.getChildren().remove(mediaView);
mediaView = new MediaView(player);
mediaView.setFitWidth(700);
mediaView.setFitHeight(700);
mediaView.setSmooth(true);
root.getChildren().add(mediaView);
}
});
// Create the HBox
HBox controlBox = new HBox(5, playButton, stopButton);
// Create the VBox
root = new VBox(5,mediaView,controlBox);
// Set the Style-properties of the HBox
root.setStyle("-fx-padding: 10;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 5;" +
"-fx-border-radius: 5;" +
"-fx-border-color: blue;");
// Create the Scene
scene = new Scene(root);
// Add the scene to the Stage
stage.setScene(scene);
// Set the title of the Stage
stage.setTitle("A simple Media Example");
// Display the Stage
stage.show();
}
}
Related
Using Winium, i'm trying to automate 'Calculator' application. Trying to identify the button object "1" or "2" or all button under numeric pad is working fine. Having same xpath description, if I trying to access the immediate text object is not working in Winium.
Below is object screen shot identified using Inspect.exe
Below is code where I try to identify all the object under "Number pad" group. Printing values only between 1-5.
package testcases;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
public class MyFirstTestCase {
public static void main(String args[]) throws MalformedURLException, InterruptedException {
DesktopOptions desktopOptions = new DesktopOptions();
desktopOptions.setApplicationPath("C:\\Windows\\System32\\calc.exe");
WiniumDriver winiumDriver = new WiniumDriver(new URL("http://localhost:9999"), desktopOptions);
try {
Thread.sleep(5000);
List<WebElement> webElements =
winiumDriver.findElements(
By.xpath("/*[#Name='Calculator' and #LocalizedControlType='window']"
+ "/*[#Name='Calculator' and #LocalizedControlType='window']"
+ "//*[#LocalizedControlType='group' and #ClassName='LandmarkTarget']"
+ "/*[#Name='Number pad' and #ClassName='NamedContainerAutomationPeer']"
+ "/*[#LocalizedControlType='button']"
));
System.out.println("Length[webElements]:"+webElements.size());
Thread.sleep(3000);
for(int index=1;index<6;index++) {
System.out.println(webElements.get(index).getAttribute("Name"));
//webElements.get(index).click();
Thread.sleep(1000);
}
#SuppressWarnings("deprecation")
Process process = Runtime.getRuntime().exec("taskkill /f /t /IM calc.exe");
process.waitFor();
process.destroy();
} catch(Exception e) {
System.out.println(e.getStackTrace());
e.printStackTrace();
// winiumDriver.close();
// winiumDriver.quit();
}
}
}
Output:
Length[webElements]:11
One
Two
Three
Four
Five
If i try to add the last child item which is text object. findElements is not identifying the object.
Screen shot of image from Inspect.exe for text object.
Only change to above code is child selector added.
List<WebElement> webElements =
winiumDriver.findElements(
By.xpath("/*[#Name='Calculator' and #LocalizedControlType='window']"
+ "/*[#Name='Calculator' and #LocalizedControlType='window']"
+ "//*[#LocalizedControlType='group' and #ClassName='LandmarkTarget']"
+ "/*[#Name='Number pad' and #ClassName='NamedContainerAutomationPeer']"
+ "/*[#LocalizedControlType='button']"
+ "//*[#ClassName='TextBlock']"
));
Even tried, + "//[#ClassName='TextBlock']" with "/[#LocalizedControlType='text']", but no use. It always return length as 0, if I try to give last child element [text].
Same is working fine if I try to give object description till button.
Let me know if i'm missing something.
Regards,
Ramkumar
I tried displaying the google web page on my javafx view using webview. All it does is display an empty page. For testing I did add a text element at the bottom and it did show up. Any pointers would be helpful. My code and the sample screen are attached.
I am running this application on a Windows 7 machine with 8 GB RAM and this is deployed in an environment that needs proxy authentication.
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class MyBrowser extends Application
{
private Pane root;
#Override
public void start(final Stage stage) throws URISyntaxException
{
root = new VBox();
List<Proxy> proxies = ProxySelector.getDefault().select(new URI("http://www.google.com"));
final Proxy proxy = proxies.get(0); // ignoring multiple proxies to simplify code snippet
if (proxy.type() != Proxy.Type.DIRECT)
{
// you can change that to dialog using separate Stage
final TextField login = new TextField("login");
final PasswordField pwd = new PasswordField();
Button btn = new Button("Login");
btn.setOnAction(new EventHandler<ActionEvent>()
{
public void handle(ActionEvent t)
{
System.setProperty("http.proxyUser", login.getText());
System.setProperty("http.proxyPassword", pwd.getText());
displayWebView();
}
});
root.getChildren().addAll(login, pwd, btn);
}
else
{
displayWebView();
}
stage.setScene(new Scene(root, 400, 600));
stage.show();
}
private void displayWebView()
{
root.getChildren().clear();
WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
root.getChildren().addAll(webView, new Text("HELLO"));
webEngine.load("http://www.google.com");
}
public static void main(String[] args)
{
launch();
}
}
I copied and pasted your code and ran it on Windows 7 with Java7u40 both Java8b108.
In both cases the code functioned correctly and displayed the http://www.google.com page.
The proxy selector code in your source was not triggered for me (probably because I have a Proxy.Type.DIRECT connection, so there was nothing for it to do).
I have a problem using the JavaFX WebView. What I want to achieve is pre-fetching a web page in the background and visualiszing it only when the page is totally loaded.
I have made a simple exmaple program to reproduce the problem. After the page is loaded I enable a button. A Click on this button then makes the WebView visible.
The problem I have is, that if I click on the button when it gets enabled, the web page is not visible directly. Instead the following happens: At first there is a totally white panel and then after a short time the web page is visible. I don't understand why the page is not visible directly. How can I achieve it, that the web page is directly visible?
The following link points to an animated gif which shows the behaviour:
http://tinypic.com/view.php?pic=oh66bl&s=5#.Ujmv1RddWKk
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class WebViewTest extends javax.swing.JPanel {
private static JFXPanel browserFxPanel;
private WebView webView;
private WebEngine eng;
/**
* Creates new form WebViewTest
*/
public WebViewTest() {
initComponents();
Platform.setImplicitExit(false);
browserFxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
public void run() {
webView = createBrowser();
Scene scene = new Scene(webView);
scene.setFill(null);
browserFxPanel.setScene(
scene);
}
});
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
* content of this method is always regenerated by the Form Editor.
*/
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
pnlMain = new javax.swing.JPanel();
showWebpageButton = new javax.swing.JButton();
setLayout(new java.awt.GridBagLayout());
pnlMain.setLayout(new java.awt.BorderLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(pnlMain, gridBagConstraints);
showWebpageButton.setText("show web page");
showWebpageButton.setEnabled(false);
showWebpageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showWebpageButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
add(showWebpageButton, gridBagConstraints);
}// </editor-fold>
private void showWebpageButtonActionPerformed(java.awt.event.ActionEvent evt) {
pnlMain.removeAll();
pnlMain.add(browserFxPanel, BorderLayout.CENTER);
WebViewTest.this.invalidate();
WebViewTest.this.revalidate();
}
// Variables declaration - do not modify
private javax.swing.JPanel pnlMain;
private javax.swing.JButton showWebpageButton;
// End of variables declaration
private WebView createBrowser() {
Double widthDouble = pnlMain.getSize().getWidth();
Double heightDouble = pnlMain.getSize().getHeight();
final WebView view = new WebView();
view.setMinSize(widthDouble, heightDouble);
view.setPrefSize(widthDouble, heightDouble);
eng = view.getEngine();
eng.load("http://todomvc.com/architecture-examples/angularjs/#/");
eng.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
final double workDone = eng.getLoadWorker().getWorkDone();
final double totalWork = eng.getLoadWorker().getTotalWork();
if (workDone == totalWork) {
showWebpageButton.setEnabled(true);
}
}
});
return view;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final JFrame f = new JFrame("Navigator Dummy");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(new Dimension(1024, 800));
final WebViewTest navDummy = new WebViewTest();
f.getContentPane().add(navDummy);
f.setVisible(true);
}
});
}
}
JFX needs a "stage" to show up its face. Modify your codes as following and it will work perfectly
/**
* Creates new form WebViewTest
*/
private Stage stage; // insert this line
public WebViewTest() {
initComponents();
Platform.setImplicitExit(false);
browserFxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
public void run() {
webView = createBrowser();
Scene scene = new Scene(webView);
scene.setFill(null);
stage = new Stage(); // <<<
stage.setScene(scene); // <<<
browserFxPanel.setScene(scene);
}
});
}
...
private void showWebpageButtonActionPerformed(java.awt.event.ActionEvent evt) {
pnlMain.removeAll();
pnlMain.add(browserFxPanel, BorderLayout.CENTER);
WebViewTest.this.invalidate();
WebViewTest.this.revalidate();
stage.show(); // <<< afer click Button
}
I am trying to scan QR code with my code. My code is running fine with 5.0(Bold) and 7.1(Torch) OS phones. It is running fine with 7.1 and 5.0. but giving problem while running with 6.0 OS(Bold 9700). The problem is - "While trying to scan QR code, app scans the QR code but camera screen doesn't pop and it remains at the front. Event it is not able to hide by using Esc key". please help me to resolve the issue with os6.
Edit:
Code while opening camera screen for QR code scan:
Hashtable hints = new Hashtable();
// The first thing going in is a list of formats. We could look for
// more than one at a time, but it's much slower.
Vector formats = new Vector();
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
// We will also use the "TRY_HARDER" flag to make sure we get an
// accurate scan
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
// We create a new decoder using those hints
BarcodeDecoder decoder = new BarcodeDecoder(hints);
// Finally we can create the actual scanner with a decoder and a
// listener that will handle the data stored in the QR code. We put
// that in our view screen to handle the display.
try {
_scanner = new BarcodeScanner(decoder, new LeadQRcodeDecoderListener());
_QRcodeScreen = new LeadQRcodeScannerViewScreen(_scanner);
// If we get here, all the QR code scanning infrastructure should be set
// up, so all we have to do is start the scan and display the viewfinder
_scanner.startScan();
UiApplication.getUiApplication().pushScreen(_QRcodeScreen);
}
catch (Exception e) {
e.printStackTrace();
return;
}
code for closing screen is:
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(_QRcodeScreen);
}
});
I am calling this code after scanning of QR code.
This is a problem with OS6 in some devices that has been asked before on this site. Last one was two days ago:
Blackberry OS6 camera wont shut down after capture
AFAIK there's no API to close the camera app, so it has to be done with key injection hacks, that are tricky because they need accurate timing and as CPUs are different in some models, and also because the camera app has a different design in some OSes.
So either you use JSR135 and use a renamed Zxing package to provide a camera view contained in your app, or just follow your approach but instead of closing the camera app you just bring to foreground your own app.
I have solved my same issue for os 6. After scanning of QR code, close all player and scanner connection.
You can use-
if (_scanner != null && _scanner.getPlayer() != null) {
_scanner.getPlayer().close();
}
It is helpful to me.
This will definitely help you.
here is my code , it's working perfectly in OS 6.0 device 9830
/**
* First Invoke the QR Scanner
*/
ViewFinderScreen _viewFinderScreen =
new ViewFinderScreen(ShoopingCartScreen.this); // ShoopingCartScreen.this Current Screen Object
UiApplication.getUiApplication().pushScreen(_viewFinderScreen);
package com.application.qrScanner;
import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import net.rim.device.api.barcodelib.BarcodeDecoder;
import net.rim.device.api.barcodelib.BarcodeDecoderListener;
import net.rim.device.api.barcodelib.BarcodeScanner;
import net.rim.device.api.io.Base64InputStream;
import net.rim.device.api.io.http.HttpDateParser;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
import com.application.data.ShoopingCartObj;
import com.application.global.Global;
import com.application.log.Log;
import com.application.main.MessageScreen;
import com.application.main.orderDetail.orderSection.InputPopUpScreen;
import com.application.main.shoopingSection.ShoopingCartScreen;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
public class ViewFinderScreen extends MainScreen
{
private BarcodeScanner _scanner;
private short _frequency = 1046;
private short _duration = 200;
private int _volume = 100;
private VideoControl vc;
private ButtonField _btnCancel;
private ShoopingCartScreen _shoopingCartScreen;
/**
* Creates a new ViewFinderScreen object
*/
public ViewFinderScreen(ShoopingCartScreen _shoopingCartScreen)
{
this._shoopingCartScreen = _shoopingCartScreen;
_btnCancel = new ButtonField("Cancel" , ButtonField.USE_ALL_WIDTH)
{
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(1);
return true;
}
};
_btnCancel.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
stopScan();
UiApplication.getUiApplication().popScreen(ViewFinderScreen.this);
}
});
// Initialize Hashtable used to inform the scanner how to
// recognize the QR code format.
Hashtable hints = new Hashtable();
Vector formats = new Vector(1);
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
// Initialize the BarcodeDecoder
BarcodeDecoder decoder = new BarcodeDecoder(hints);
// Create a custom instance of a BarcodeDecoderListener to pop the
// screen and display results when a QR code is recognized.
BarcodeDecoderListener decoderListener = new BarcodeDecoderListener()
{
/**
* #see BarcodeDecoderListener#barcodeDecoded(String)
*/
public void barcodeDecoded(String rawText)
{
try {
String encoded = rawText;
byte[] decoded = Base64InputStream.decode( encoded );
rawText = new String(decoded);
System.out.println( new String( decoded ) );
}
catch (Throwable t) {
System.out.println( "Unable to decode string: " + t.getMessage() );
}
displayMessage(rawText);
ViewFinderScreen.this. _shoopingCartScreen.beep();
}
};
try
{
// Initialize the BarcodeScanner object and add the associated
// view finder.
_scanner = new BarcodeScanner(decoder, decoderListener);
vc = _scanner.getVideoControl();
vc.setDisplayFullScreen(true);
add(_scanner.getViewfinder());
setStatus(_btnCancel);
}
catch(Exception e)
{
displayMessage("Initilize Scanner: " + e.getMessage());
}
startScan();
}
/**
* Informs the BarcodeScanner that it should begin scanning for QR Codes
*/
public void startScan()
{
try
{
_scanner.startScan();
}
catch(MediaException me)
{
displayMessage(" Start Scan Error: " + me.getMessage());
}
}
public void stopScan()
{
try
{
Player p = _scanner.getPlayer() ;
if(p != null)
{
p.stop();
p.deallocate();
p.close();
}
}
catch (Exception e)
{
MessageScreen.msgDialog("Exception in Stop Scanning "+e.toString());
}
}
/**
* Pops the ViewFinderScreen and displays text on the main screen
*
* #param text Text to display on the screen
*/
private void displayMessage(final String text)
{
Log.d("QR Code String ", text);
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
stopScan();
}
});
}
protected boolean keyDown(int keycode, int time)
{
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE)
{
stopScan();
return true;
}
return super.keyDown(keycode, time);
}
}
Is it possible to to overlay any JavaFx2 widgets or canvas on top of a JavaFX 2 webview?
I want to generate a transparent heatmap by means of JavaFX 2 on top of a webview.
Adding overlay is very easy: just put webview and any pane to StackPane.
Another story is to synchronize overlay and webview data. To achieve that you need to ask webview for object coordinates through javascript. Here is an example which finds stackoverflow question area and marks it on overlay:
public class WebOverlay extends Application {
#Override
public void start(Stage stage) {
StackPane root = new StackPane();
WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
Canvas overlay = new Canvas(600,600);
overlay.setOpacity(0.5);
final GraphicsContext gc = overlay.getGraphicsContext2D();
gc.setFill(Color.RED);
root.getChildren().addAll(webView, overlay);
stage.setScene(new Scene(root, 600, 600));
webEngine.getLoadWorker().workDoneProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.intValue() == 100) {
// find coordinates by javascript call
JSObject bounds = (JSObject)webEngine.executeScript("document.getElementsByClassName('question-hyperlink')[0].getBoundingClientRect()");
Number right = (Number)bounds.getMember("right");
Number top = (Number)bounds.getMember("top");
Number bottom = (Number)bounds.getMember("bottom");
Number left = (Number)bounds.getMember("left");
// paint on overlaing canvas
gc.rect(left.doubleValue(), top.doubleValue(), right.doubleValue(), bottom.doubleValue());
gc.fill();
}
});
webEngine.load("http://stackoverflow.com/questions/10894903/how-to-make-an-overlay-on-top-of-javafx-2-webview");
stage.show();
}
public static void main(String[] args) { launch(); }
}
Do you mean something like this:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextBuilder;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Demo extends Application {
#Override
public void start(Stage primaryStage) {
WebView webView = new WebView();
webView.getEngine().load("http://www.google.com");
StackPane root = new StackPane();
root.getChildren().addAll(webView, getOverlay());
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
private Pane getOverlay() {
StackPane p = new StackPane();
Rectangle r = RectangleBuilder.create()
.height(100).width(100)
.arcHeight(40).arcWidth(40)
.stroke(Color.RED)
.fill(Color.web("red", 0.1))
.build();
Text txt=TextBuilder.create().text("Overlay")
.font(Font.font("Arial", FontWeight.BOLD, 18))
.fill(Color.BLUE)
.build();
p.getChildren().addAll(r, txt);
return p;
}
public static void main(String[] args) {
launch(args);
}
}