WebFrame now working after all

This commit is contained in:
Ben Fry
2021-07-08 17:38:16 -04:00
parent 3c40f32d52
commit cf91432ec4
2 changed files with 25 additions and 5 deletions
+2 -2
View File
@@ -39,8 +39,8 @@
</target>
<target name="run" depends="build" description="Run standalone for development">
<!-- <java classname="processing.app.tools.WebFrame" fork="true"> -->
<java classname="processing.app.tools.SimpleSwingBrowser" fork="true">
<java classname="processing.app.tools.WebFrame" fork="true">
<!-- <java classname="processing.app.tools.SimpleSwingBrowser" fork="true"> -->
<sysproperty key="java.library.path" value="${javafx.path}" />
<classpath>
@@ -10,6 +10,8 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import static javafx.concurrent.Worker.State.FAILED;
public class WebFrame extends JFrame {
@@ -65,12 +67,30 @@ public class WebFrame extends JFrame {
private void createScene() {
Platform.runLater(() -> {
//Scene scene = new Scene();
WebView view = new WebView();
engine = view.getEngine();
engine.titleProperty().addListener((observable, oldValue, newValue) -> SwingUtilities.invokeLater(() -> WebFrame.this.setTitle(newValue)));
engine.setOnStatusChanged(event -> SwingUtilities.invokeLater(() -> lblStatus.setText(event.getData())));
engine.locationProperty().addListener((ov, oldValue, newValue) -> SwingUtilities.invokeLater(() -> txtURL.setText(newValue)));
engine.getLoadWorker().workDoneProperty().addListener((observableValue, oldValue, newValue) -> SwingUtilities.invokeLater(() -> progressBar.setValue(newValue.intValue())));
engine.getLoadWorker()
.exceptionProperty()
.addListener((o, old, value) -> {
if (engine.getLoadWorker().getState() == FAILED) {
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(
panel,
(value != null)
? engine.getLocation() + "\n" + value.getMessage()
: engine.getLocation() + "\nUnexpected error.",
"Loading error...",
JOptionPane.ERROR_MESSAGE));
}
});
jfxPanel.setScene(new Scene(view));
});
}