Using the Swing Component

Lee Painter

Setting up

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

<dependencies>
   <dependency>
      <groupId>com.sshtools</groupId>
      <artifactId>terminal-swing</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

Now create a Java class with main method for execution. You will need the following imports:

import com.sshtools.terminal.vt.swing.SwingTerminalPanel;
import com.sshtools.terminal.vt.swing.SwingScrollBar;
import javax.swing.JFrame;
import java.awt.BorderLayout;

First off you'll need the actual Swing component. This can be added to your UI as any other component would be.

JFrame frame = new JFrame("Terminal");
frame.setLayout(new BorderLayout());
SwingTerminalPanel display = new SwingTerminalPanel();
frame.add(display, BorderLayout.CENTER);

You probably want a scrollbar to allow scrolling back through previous output:

frame.add(new SwingScrollBar(display), BorderLayout.EAST);

Now pack and display your frame:

frame.pack();
frame.setVisible(true);

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.