Using the JavaFX Component

Lee Painter

Setting up

You will first need to import the terminal-javafx module in your maven project.

<dependencies>
   <dependency>
      <groupId>com.sshtools</groupId>
      <artifactId>terminal-javafx</artifactId>
      <version>3.0.0-SNAPSHOT</version>
   </dependency>
</dependencies>
<repositories>
   <repository>
      <id>sshtools</id>
      <name>sshtools</name>
      <url>http://artifactory.javassh.com/opensource-releases</url>
   </repository>
</repositories>

Creating the Terminal Display

The structure of a JavaFX application is slightly different. For standalone applications, you generally extend Application and override the start(Stage) method. If you already have a component you wish to embed a terminal into, use a reference to that instead:

@Override
public void start(Stage primaryStage) {
    // insert code here ...
}

Create the JavaFX terminal component:

JavaFXTerminalPanel display = new JavaFXTerminalPanel();

You will need to put the component in some kind of container before adding to the scene:

BorderPane displayContainer = new BorderPane();
displayContainer.setCenter(display.getControl());

Now set the scene of the stage using the display container:

primaryStage.setTitle("FXTerm");
primaryStage.setScene(new Scene(displayContainer));
primaryStage.show();

You will next need to obtain a reference to the terminal and connect the terminal to a remote host. Return to the article Integrating a Terminal Into Your Application to complete this.