public interface GravitonRunInShell
Simply return your intended top level scene from createScene(Graviton).
This method will be called *before* Application.start(Stage), so you should move any
initialisation code you need into this method instead. You will still receive a call to
Application.start(Stage) however, the stage is already configured with a new title, etc.
You should therefore change your start method to leave the stage well alone if it's already visible, as this
indicates Graviton configured it for you. In this way you can write an app that behaves well whether it's run inside
or outside the shell.
You will receive a Graviton object that will let you interrogate your environment and access various features
exposed by the browser. There's no other way to get to it at the moment so stash a reference to it somewhere safe.
You don't have to write a JavaFX app to benefit from this feature. For example, a Swing app could implement this
interface on its main class and then return a scene containing a SwingNode to benefit
in the same way.
Be aware:
System.exit(int). In future these sorts of operations
may be blocked.Here's an example of how you might adapt a typical JavaFX application:
public class MyApp extends Application implements GravitonRunInShell {
public Scene createScene(Graviton graviton, double width, double height) {
Button root = new Button("Hello world!");
if (graviton != null)
return new Scene(root, graviton.getWidth(), graviton.getHeight()); // Fill the browser area.
else
return new Scene(root);
}
public void start(Stage primaryStage) {
primaryStage.setTitle("My App");
if (primaryStage.isShowing()) return; // Running in Graviton so bail out.
// Running outside of Graviton, set up the stage.
primaryStage.setScene(createScene(null));
primaryStage.show();
}
}
| Modifier and Type | Method and Description |
|---|---|
javafx.scene.Scene |
createScene(Graviton graviton)
Called after your main class is created.
|
javafx.scene.Scene createScene(Graviton graviton)
graviton - A reference to a control interface for the browser.