TCP socket. jexer.demos.Demo3 demonstrates how one might use a
character encoding than the default UTF-8.
-* Java Swing UI. The default window size for Swing is 80x25, which is
- set in jexer.session.SwingSession. For the demo applications, this
- is the default backend on Windows and Mac platforms. This backend
- can be explicitly selected for the demo applications by setting
- jexer.Swing=true.
+* Java Swing UI. The default window size for Swing is 80x25 and 20
+ point font; this can be changed in the TApplication(BackendType)
+ constructor. For the demo applications, this is the default backend
+ on Windows and Mac platforms. This backend can be explicitly
+ selected for the demo applications by setting jexer.Swing=true.
Additional backends can be created by subclassing
jexer.backend.Backend and passing it into the TApplication
switch (backendType) {
case SWING:
+ // The default SwingBackend is 80x25, 20 pt font. If you want to
+ // change that, you can pass the extra arguments to the
+ // SwingBackend constructor here. For example, if you wanted
+ // 90x30, 16 pt font:
+ //
+ // backend = new SwingBackend(this, 90, 30, 16);
backend = new SwingBackend(this);
break;
case XTERM:
private SwingTerminal terminal;
/**
- * Public constructor.
+ * Public constructor. The window will be 80x25 with font size 20 pts.
*
* @param listener the object this backend needs to wake up when new
* input comes in
*/
public SwingBackend(final Object listener) {
+ this(listener, 80, 25, 20);
+ }
+
+ /**
+ * Public constructor.
+ *
+ * @param listener the object this backend needs to wake up when new
+ * input comes in
+ * @param windowWidth the number of text columns to start with
+ * @param windowHeight the number of text rows to start with
+ * @param fontSize the size in points. Good values to pick are: 16, 20,
+ * 22, and 24.
+ */
+ public SwingBackend(final Object listener, final int windowWidth,
+ final int windowHeight, final int fontSize) {
+
// Create a screen
- SwingScreen screen = new SwingScreen();
+ SwingScreen screen = new SwingScreen(windowWidth, windowHeight,
+ fontSize);
this.screen = screen;
// Create the Swing event listeners
* Public constructor.
*
* @param screen the Screen that Backend talks to
+ * @param fontSize the size in points. Good values to pick are: 16,
+ * 20, 22, and 24.
*/
- public SwingFrame(final SwingScreen screen) {
+ public SwingFrame(final SwingScreen screen, final int fontSize) {
this.screen = screen;
setDOSColors();
getContextClassLoader();
InputStream in = loader.getResourceAsStream(FONTFILE);
Font terminusRoot = Font.createFont(Font.TRUETYPE_FONT, in);
- Font terminus = terminusRoot.deriveFont(Font.PLAIN, 20);
+ Font terminus = terminusRoot.deriveFont(Font.PLAIN, fontSize);
setFont(terminus);
gotTerminus = true;
} catch (Exception e) {
e.printStackTrace();
// setFont(new Font("Liberation Mono", Font.PLAIN, 24));
- setFont(new Font(Font.MONOSPACED, Font.PLAIN, 24));
+ setFont(new Font(Font.MONOSPACED, Font.PLAIN, fontSize));
}
pack();
/**
* Public constructor.
+ *
+ * @param windowWidth the number of text columns to start with
+ * @param windowHeight the number of text rows to start with
+ * @param fontSize the size in points. Good values to pick are: 16, 20,
+ * 22, and 24.
*/
- public SwingScreen() {
+ public SwingScreen(final int windowWidth, final int windowHeight,
+ final int fontSize) {
+
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- SwingScreen.this.frame = new SwingFrame(SwingScreen.this);
+ SwingScreen.this.frame = new SwingFrame(SwingScreen.this,
+ fontSize);
SwingScreen.this.sessionInfo =
new SwingSessionInfo(SwingScreen.this.frame,
- frame.textWidth,
- frame.textHeight);
+ frame.textWidth, frame.textHeight,
+ windowWidth, windowHeight);
SwingScreen.this.setDimensions(sessionInfo.getWindowWidth(),
sessionInfo.getWindowHeight());
* @param frame the Swing Frame
* @param textWidth the width of a cell in pixels
* @param textHeight the height of a cell in pixels
+ * @param windowWidth the number of text columns to start with
+ * @param windowHeight the number of text rows to start with
*/
public SwingSessionInfo(final Frame frame, final int textWidth,
- final int textHeight) {
+ final int textHeight, final int windowWidth, final int windowHeight) {
- this.frame = frame;
- this.textWidth = textWidth;
- this.textHeight = textHeight;
+ this.frame = frame;
+ this.textWidth = textWidth;
+ this.textHeight = textHeight;
+ this.windowWidth = windowWidth;
+ this.windowHeight = windowHeight;
}
/**