Instant Download Frontend Development With JavaFX and Kotlin: Build State-of-the-Art Kotlin GUI Applications Peter Späth PDF All Chapter
Instant Download Frontend Development With JavaFX and Kotlin: Build State-of-the-Art Kotlin GUI Applications Peter Späth PDF All Chapter
com
https://ebookmeta.com/product/frontend-development-with-
javafx-and-kotlin-build-state-of-the-art-kotlin-gui-
applications-peter-spath/
OR CLICK BUTTON
DOWNLOAD NOW
Frontend Development
with JavaFX and Kotlin
Build State-of-the-Art Kotlin GUI Applications
Peter Späth
Leipzig, Sachsen, Germany
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-
800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media,
LLC is a California LLC, and the sole member (owner) is Springer Science + Business Media Finance Inc. (SSBM Finance
Inc). SSBM Finance Inc. is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint, paperback, or audio rights,
please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also
available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/
bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (https://
github.com/Apress). For more detailed information, please visit https://www.apress.com/gp/services/source-code.
1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Gradle for JavaFX and Kotlin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
A HelloWorld Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Setting Up for Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Setting Up for IntelliJ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Kotlin and Java Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
A Note About Kotlin Utilities for JavaFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
A Note About FXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
A Note About Downloading JavaFX Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Build Setup for This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Why you Should use Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
One-Way and Two-Way Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Custom Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
About Observable Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3 Stages and Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
About Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Using Stages and the Application Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Dialog-Like Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
The JavaFX Application Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
About Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Position and Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Mnemonic and Accelerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Node Lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Snapshots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Fill and Other Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Mouse Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Mouse Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
v
vi Contents
7 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
What Events Are and Event Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Event Handlers and Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Drag and Drop Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
8 Effects and Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
About Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Animating Your Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Timeline Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
9 Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The JavaFX Concurrency Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
About Kotlin Coroutines for JavaFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
About the Author
Peter Späth graduated in 2002 as a physicist and soon afterward became an IT consultant, mainly for
Java-related projects. In 2016, he decided to concentrate on writing books on various aspects, but with
a main focus on software development. With two books about graphics and sound processing, three
books on Android app development, and a couple of books about Java, Jakarta EE, and Kotlin, Peter
continues his effort in writing software development-related literature.
ix
About the Technical Reviewer
xi
Introduction
Building elegant and highly responsible, responsive, and stable Java client applications (fat clients)
is a highly acceptable approach if security considerations or network availability speaks against
web applications, or maintaining servers and server applications lies out of scope for your project.
Additionally, using Kotlin as a programming language boosts code expressiveness and maintainability,
allowing for a development yielding a clean code approach.
The book introduces JavaFX as a frontend technology and from the very beginning focuses
on using Kotlin instead of Java for coding the program artifacts. Many listings and code snippets
accompany the text, readily allowing for a hands-on learning style.
The book is for low- to mid-level Java or Kotlin developers with or without JavaFX experience,
wishing to learn how to build JavaFX applications with Kotlin.
The readers will in the end be able to use Kotlin as a language for building basic to moderately
advanced and elaborated apps targeting JavaFX.
Any experience in using JavaFX and frontend coding is not a requirement for reading the book.
Being a Kotlin expert is not necessary either, but having read introductory-level books or studied
online resources is surely helpful. The online documentation of Kotlin and JavaFX also provides
valuable resources you can use as a reference while reading this book.
Source Code
All source code shown or referred to in this book can be found at github.com/apress/frontend-
development-javafx-kotlin.
This book should be read sequentially to get the most benefit from it. Of course, you can skip one
or the other chapter if you already gained knowledge elsewhere. Taking its introductory nature, the
book is not meant to present a reference fully covering each and every aspect of Kotlin frontend
programming or JavaFX, so also consulting the online documentation at
https://openjfx.io/
https://openjfx.io/javadoc/19/
https://kotlinlang.org/docs/home.html
xiii
xiv Introduction
while you are reading the book certainly is not a bad idea.
The book is split up into nine chapters. Chapter 1 gives a general introduction and presents hello
world-style programs for Gradle, Eclipse, and IntelliJ.
Chapter 2 talks about using properties as data holders and addresses one- and two-way binding
techniques for connecting controls and data in your program.
Chapter 3 introduces stages and scenes, which serve as primordial containers for visual artifacts.
Chapter 4 talks about containers and ways to lay out and style your scenes.
Chapter 5 handles nodes and controls including styling. These aspects usually constitute the biggest
part of your project work speaking of time budget.
Chapter 6 presents lists and tables, which are particularly important for enterprise-level projects.
Chapter 7 is for summarizing and deepening our knowledge about event handling in JavaFX. This
also includes drag and drop procedures.
Chapter 8 introduces effects and animation, improving user experience and giving your programs
some eye candies.
As a prospect, Chapter 9 briefly introduces concurrency techniques, giving you a starting point for
handling background processing needs.
Getting Started
1
In this chapter, we give a brief introduction to using JavaFX and Kotlin together, and we create “Hello
World”–style projects for the command line, for Eclipse, and for IntelliJ IDEA.
Introduction
JavaFX is the dedicated fat client (desktop application) GUI toolkit for current Java releases. It is
the replacement and successor of the venerable Java Swing technology. This switch happened around
2010, and since then JavaFX has been constantly improved and extended. With JREs up to version
JDK 9, JavaFX was part of the Java distribution—with JDK 11 and later, it has to be installed
separately.
The following features describe JavaFX:
. Built-in controls: Labels, editable text fields, buttons, combo boxes, checkboxes, radio buttons,
menu bars, scrollbars, accordion, tabs, canvas (for drawing shapes and figures), color picker, pag-
ination, 3D graphics (games, science, product presentation), WebView (presenting and interacting
with web contents), dialogs, sliders, spinners, progress bars
. Lists, tables, trees
. Built-in layouts: AnchorPane (anchoring nodes to one of the edges or to the center point),
BorderPane (placing nodes at bottom, top, right, left, center), FlowPane (placing nodes consec-
utively and wrapping at the boundaries), TilePane (same as FlowPane, but with all cells the same
size), GridPane (placing nodes in a grid with cell sizes dynamically calculated and on demand
spanning several rows and columns), VBox (placing nodes in columns), HBox (placing nodes in
rows), StackPane (placing nodes in an overlay fashion)
. Animation (fade, fill, stroke, translate, rotate, scale, . . . ), effects (glow, blend, bloom, blur,
reflection, sepia, shadow, lighting)
. Nodes stylable via CSS
. Some built-in chart widgets
. Flexible and concise data binding via observable properties
. Descriptive layouting via FXML
. Module support (for JDK 9+)
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023 1
P. Späth, Frontend Development with JavaFX and Kotlin,
https://doi.org/10.1007/978-1-4842-9717-9_1
2 1 Getting Started
In this book, we describe a subset of these features, giving you a starting point for your own
projects.
Using Kotlin as a programming language instead of Java gives a boost to your coding experience.
Just to give you an example, consider a button with a click handler. In Java, you’d write
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
With 142 characters, this is more than 40% shorter than the Java variant! And besides being shorter,
it is also more expressive and by that easier to understand and easier to maintain.
Using some sufficiently nonobtrusive utility functions, this can even be further reduced to 81
characters in size:
val btn = Button("Say 'Hello World'") {
println("Hello World!")
}
As a build tool, we use Gradle from https://gradle.org/. It is highly flexible, works on any operating
system that provides a Java installation, and by means of plugins or preinstalled components can be
operated from many IDEs.
I first describe the CLI mode for running Gradle builds. This is how you would use it in a server
environment, but it also serves as a good starting point if you want to learn how to use Gradle inside
an IDE workflow.
If not already present, get and install a version 17 JDK. Throughout the book, we will be using
OpenJDK 17, but if chances are good you can also take Oracle’s supported JDK 17 or a higher version
from either Oracle or https://openjdk.org/ without any problems possibly coming up.
Gradle for JavaFX and Kotlin 3
Note Using Oracle’s JDK 17 or higher requires buying a license if you plan to use it for a longer
term; see www.oracle.com/java/.
As a next step, fetch Gradle from https://gradle.org. In this book, we use version 7.6 from https://
gradle.org/next-steps/?version=7.6&format=bin. In order to announce Java to Gradle, either make
sure java and javac (with .bat extension on Windows) are in your PATH, or you have the
environment variable JAVA_HOME point to your JDK installation folder (recommended). To simplify
using Gradle, you can also put GRADLE-INST-DIR/bin (with GRADLE-INST-DIR pointing to your
Gradle folder), or GRADLE-INST-DIR\bin for Windows, on the path.
Note In Linux, environment variables like PATH or JAVA_HOME get set via
export PATH=/bin:/usr/bin:/path/to/my/gradle/bin.
In Windows, you must use the system settings dialog.
Kotlin: 1.7.10
Groovy: 3.0.13
Ant: Apache Ant(TM) version 1.10.11 compiled on
July 10 2021
JVM: 17.0.1 (Oracle Corporation 17.0.1+12-39)
OS: Linux 5.15.0-56-generic amd64
Important is the “JVM:” line. The Kotlin version shown does not mean you would not be able to build
applications running under a different Kotlin version—it just tells it is using Kotlin 1.7.10 for its own
purposes.
Next, create a project folder anywhere on your system. For our example project, we call it
HelloWorld. Change into that folder:
cd /path/to/HelloWorld (Linux)
chdir C:\path\to\HelloWorld (Windows)
You can also enter just gradle init, but then you will subsequently be asked for project
coordinates inside the terminal.
4 1 Getting Started
The “init” task creates a simple scaffold project which consists of a main project described by
file settings.gradle and a subproject called “app” in the accordingly named subfolder. The
application can be run by just entering either of
gradle app:run
gradle run
The second variant is possible, because there is just one subproject. By the way, you can list all
possible tasks via gradle tasks or gradle tasks --all, and entering gradle help shows
more info.
Did you notice that two executable files gradlew and gradlew.bat and a folder gradle were
created? This is the Gradle Wrapper, and it is a Gradle installation on its own, and you can henceforth
use it to build the project. Just use gradlew from the wrapper instead of gradle from the Gradle
distribution. You can even delete the main Gradle installation folder at this time, if you like.
It is now time to add JavaFX to the project. In Gradle, the build.gradle file is the main
configuration file for the build process. You can find it inside the app subproject inside the app folder.
Open the file inside a text editor, and inside the plugins { . . . } section, add
plugins {
...
id 'org.openjfx.javafxplugin' version '0.0.13'
}
This plugin adds almost all that is necessary to add JavaFX to a Java or Kotlin project. Kotlin
capabilities were already added during gradle init. We however still need to make sure that
Kotlin compiles for JDK 17 and that JavaFX uses version 19 and allows for using the modules
“javafx.controls” and “javafx.graphics”. For that aim, add at the end of build.gradle
compileKotlin {
kotlinOptions {
suppressWarnings = true
jvmTarget = "17"
}
}
javafx {
version = "19"
modules("javafx.controls", "javafx.graphics")
}
Note JavaFX is separated into different modules. The modules “javafx.base”, “javafx.controls”, and
“javafx.graphics” are essential to almost any JavaFX application. Because both the controls and the
graphics module require the base module, the latter gets implicitly included in any build and can be
omitted from the modules list. For more details, see https://openjfx.io/javadoc/19/
In the next section, we code our little “Hello World” JavaFX with Kotlin application.
A HelloWorld Project
The scaffold project built via gradle init just prints “Hello World!” on the console if run. As a
starter JavaFX project, we instead want to show a little window with a button on it reacting to press
events. To do so, replace the contents of
app/src/main/kotlin/book/kotlinfx/App.kt
Other documents randomly have
different content
The Project Gutenberg eBook of Harry Muir
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
BY THE AUTHOR OF
“PASSAGES IN THE LIFE OF MRS. MARGARET MAITLAND,”
“MERKLAND,” “ADAM GRAEME,” &C.
IN THREE VOLUMES.
VOL. I.
LONDON:
HURST AND BLACKETT, PUBLISHERS,
SUCCESSORS TO HENRY COLBURN,
13, GREAT MARLBOROUGH STREET.
1853.
LONDON:
Printed by Schulze and Co., 13, Poland Street.
HARRY MUIR.
CHAPTER I.
“Housekeeping youth have ever homely wits.”
“And this is the pillar that Rob Roy hid behind, the Sabbath day that
he warned the young English gentleman in the kirk. It’s the very
place itsel. Here was the pulpit—and the seats were a’ here, and this
is the pillar that hid Rob Roy.”
A party of young men were in the crypt of Glasgow cathedral—the
little sleek, humble-looking man, who very unobtrusively acted as
Cicerone, was pointing out to them the notability, with these words.
One of the visitors turned away with a grave smile, and leaving his
companions, began to wander slowly down one of the long black
aisles. The dim withdrawing vistas—the pillars with their floral
chaplets—the singular grace and majesty of those dark and
ponderous arches—impressed him with very different associations.
The young man’s smile, slightly scornful at first, melted as he
reached the lower end, and looking up through this grand avenue,
saw the little knot of dim figures in the distance. He was glad to
escape from their laughter, and unsuitable merriment. These noble
old cloisters were too grave and solemn, to have their stillness so
invaded.
But he was not suffered long to remain uninterrupted in his
contemplative mood. “What ails Cuthbert?” said one of the younger
of the party, a lad in the transition state between boy and man. “See
to him down yonder at the very end, like a craw in the mist—I say,
Cuthbert!”
As the piping shrill voice called out his name at its highest pitch,
the young man began slowly to advance again. The lad came
forward to meet him. “What are you smiling at—what did you go
away for?”
“I was smiling at myself, John,” answered the accused.
John was curious. “What for?”
“For thinking there were things more interesting here, than the
pillar that hid Rob Roy. Come along—never mind. Where are they all
bound for, now?”
They were bound for a very dissimilar place—no other than the
crowded Broomielaw, where John’s brothers were bent upon
showing their Edinburgh cousin, Cuthbert Charteris, and an English
stranger who accompanied them, one or two fine ships belonging to
“the house” then in port. These young men were the sons of a
prosperous merchant, all of them already in harness in the office,
and beginning to make private ventures on their own behalf. There
were three of them—Richard, Alick, and John Buchanan; the two
elder had reached the full dignity of young manhood, and rejoiced in
mighty whiskers, which John, poor fellow, could only covet intensely,
and cultivate with all his might; but even John had begun to have
the shrewd man of business engrafted on the boy, and was
sometimes precociously calculating, and commercial—sometimes
disagreeably swaggering and loud—though not unfrequently simple,
foolish, and generous, as better became his years.
“I say, Cuthbert,” said the communicative John, as he swung his
arm through his grave cousin’s, and followed his gay brothers on the
way to the river, “did you ever see Harry Muir? Dick says he’s going
to make him come and dine with us to-night.”
“And who is Harry Muir?” asked Charteris.
“Oh, he’s nobody—only a clerk in the office you know—but you
never saw such a clever chap. He can sing anything you like. He’s a
grand singer. And when Harry’s in a good humour, you should just
hear him with the fellows in the office. My father looks out of his
own room sometimes to see what’s the row, and there’s Gilchrist
sucking his pen, and Macauley and Alick close down over their
books, writing for a race, and Muir quite cool, and looking as
innocent as can be. You should just see them, and see how puzzled
my father is, when he finds that there’s no row at all!”
“And in such emergencies, how do you behave yourself, Johnnie?”
“Johnnie! I wish you’d just mind that I’m not a boy now.”
“Jack, then! Will that please you, young man,” said Charteris,
smiling.
“Me? I behave the best way I can,” said the mollified John. “The
best plan is, to set to working, and never let on that you hear the
door open; but we like to get him among a lot of us when there’s
nobody in the way; and you’ll just see to-night, Cuthbert, what a
grand fellow he is for fun.”
Cuthbert did not look very much delighted. “And when is this
famous dinner to be?” he asked. “Is Dick to entertain us at home?”
Master John burst into a great laugh. “Man, Cuthbert, what a
simple fellow you are! You don’t think my mother would ask Harry
Muir to dine.”
“And why not, my boy?” asked the Edinburgh advocate.
“Why not! Man, is that the way you do in the east country? He’s
only a clerk, and everybody knows you Edinburgh folk are as proud
as proud can be. Would you ask your clerk to dine with you?”
“I don’t possess such an appendage, Sir John,” said the briefless
barrister, “except it be a little scrubby boy like what you were the
last time I was west here—and he certainly would need some
brushing up. So he’s not a gentleman, this wit of yours? He would
not be presentable in the drawing-room?”
“Hum! I don’t know,” said honest John, hesitating. “He looks quite
as well as Dick or Alick, or that Liverpool man there.” The lad drew
himself up and arranged his neckcloth complacently. “There’s
handsomer men, to be sure; but I think Muir’s better looking than
any of you, Cuthbert.”
Charteris laughed: “Is he not well-bred, then?”
“Oh yes, he can behave himself well enough. He’s got a way of his
own, you know; but then he’s a clerk.”
“And so are you, Jack, my man,” said Charteris.
“Oh yes, but there’s a difference. He’s got no money—and more
than that,” said the juvenile merchant, “he’s got no enterprise,
Cuthbert. There’s Alick, he had a share in a plan, sending out a lot of
things to San Francisco on a venture, just when the news came
about the gold, you know, and he cleared a hundred pounds; that’s
the way to do. But then, that fellow Muir, he never tries a thing; and
worse than that, he went away and married somebody last year, and
he had three sisters before, and them all living with him. Just think
of that. Four women all dragging a young man down when he might
be rising in the world. Isn’t it awful?”
“A very serious burden,” said Charteris, smiling, “but what is his
salary, John?”
“His salary’s sixty pounds; my father gives very good salaries. He’s
just a clerk, you know. The cashier has two hundred.”
“Sixty pounds! and five people live on sixty pounds!” said the
lawyer.
“And they’ve got a baby,” said John, solemnly.
It was the climax; there was no more said.
The respectable firm of George Buchanan and Sons had its office in
a dingy business street near the Exchange. The early darkness of
the February night had almost blotted out the high sombre houses
opposite, except for the gleaming gas-light streaming from office
windows in irregular patches from garret to basement. It was not a
very busy time, and at five o’clock the clerks were preparing to leave
the office.
“I say, Muir,” cried Richard Buchanan, bursting in hastily, “come and
dine with us.”
Charteris was behind. The famous Harry Muir was certainly
handsome—very much better looking than any other of the party,
and had a fine, sparkling, joyous, intelligent face—but the lines of it
had everything in them but firmness.
“Not to-night,” said the clerk, “you must not ask me to-night.”
“Why not to-night?” said the young master. “Come along now,
Harry. Do be a good fellow. Why it’s just to-night of all nights that
we want you. There’s my cousin Charteris, and there’s an
Englishman; and we’re all as flat as the Clyde. Come along, Muir,
don’t disoblige us.”
“I am very sorry,” said Muir, “but I can’t stay in town to-night. Let
me off to-night; I will be more obedient next time.”
“He wants to get home to nurse his wife,” said Buchanan, with a
sneer.
“My wife is quite well,” answered Harry, with a quick flush of anger;
“she does not need my nursing, Mr. Buchanan.”
“Mr. Buchanan! don’t be ill-natured, Harry—come along.”
“No, no; I cannot go to-night. I don’t think I can stay to-night,” said
the brilliant facile clerk.
The entreaties continued a little longer; the resistance became
feebler and more feeble, and at last, stipulating that he was to leave
them early, the genius of the counting-house consented.
“Harry, my man, send a message to your wife,” said a grave snuffy
person, who enjoyed the two hundred pounds a year of which John
had boasted, and was cashier to the Messrs. Buchanan.
Harry wavered a moment. “Where is the boy?”
“Perhaps she’ll come for you, Harry,” suggested the malicious
Buchanan.
The poor clerk threw down, angrily, the pen he had taken up, and
lifted his hat. In another minute, with quickly recovered gaiety, they
went out in a band to the adjacent square where they were to dine.
“There’s the makings of a capital man in that lad, and there’s the
makings of a blackguard,” said the grave Mr. Gilchrist, shaking his
head ruefully, and taking a pinch of snuff; “it’ll be a hard race—
which of them will win?”
The dinner in George’s-square went off very well, and the young
clerk, as he warmed, dazzled the little company; he was only a clerk
—they were inclined to patronize him at other times—but now the
unmistakeable, undesired, pre-eminence, which these young men
yielded to their poor companion, was a noticeable thing. The matter
of ambition now, was, who should seem most intimate with—who
should most attract the attention of the brilliant clerk.
Cuthbert Charteris was a more completely educated man than any
other of the party. The thorough literary training will not ally itself to
the commercial, as it seems. None of the young merchants had time
for the long discipline and athletic mental exercises of the student.
They were all making money before they should have been well
emancipated from the school-room—all independent men, when
they should have been boys—and the contrast was marked enough.
There was a good deal of boisterousness in their enjoyment, and
they were enjoying themselves heartily, while Cuthbert, getting very
weary, felt himself only preserved from utter impatience of their
mirth by the interest with which the stranger inspired him—this poor,
clever, facile Harry Muir.
The quick mind of this young man seemed to have attained
somehow to the results of education without the training and
discipline which form so principal a part of it. He seemed to have
been a desultory reader, a devourer of everything which came in his
way, and while the Buchanans knew few books beyond the serial
literature of the time, Harry threw delicate allusions about him,
which it seemed he made only for his own enjoyment, since the
arrows flew most innocently over the heads of all the rest. Threads
of connection with those great thoughts which form the common
country of imaginative minds, ideas radiating out from the centre of
these, like the lessening circles in the water—the student Cuthbert
heard and understood, and wondered—the Buchanans applauded,
and did not understand.
One of them at last proposed to go to the theatre—the rest chimed
in eagerly. Cuthbert, anxious to have the evening concluded as soon
as possible, and resolving to seek no more of the delectable society
of his young cousins except at home, where they were tolerable,
remonstrated only to be laughed at and overpowered. The grown-
up, mature, educated man resigned himself to their boyish guidance
very wearily—and what would their wit do now?
He said he would go home—he took up his hat, and played
hesitatingly with his gloves. He was excited with the company, the
applause, and a little with the wine, and was permitting himself to
parley with the tempter.
“Come along, Muir, it’s only for once; let us just have this one
night.”
“No, no.” The noes grew faint; the hesitation increased. He
consented again.
And so, louder and more boisterous than before, they again
entered the busy streets. John Buchanan was a good deal inclined to
be obstreperous. It was all that Cuthbert could manage to keep him
within bounds.
They had reached the Trongate, and Cuthbert stopped his young
companion a moment to look down the long gleaming line of the
crowded street. It had been wet in the morning, and the brilliant
light from the shop windows glistened in the wet causeway in long
lines, and the shifting groups of passengers went and came,
ceaselessly, and the hum and din of the great thoroughfare was
softened by the gloom and brightened by the light of traffic that
illuminated all.
“What are you looking at? See they’re all away across the street.
What’s the good of glowering down the Trongate? Man, Cuthbert,
how slow you are,” said John Buchanan, dragging the loiterer on.
There was a crowd on the opposite side which had absorbed the
others. Cuthbert and John crossed over.
The accident which attracted the crowd was a very common one—
an overtasked horse, wearied with the long day’s labour, had
stumbled and fallen; and now, the weight of the cart to which it was
attached having been removed, was making convulsive plunges in
the effort to rise. The carters, and the kindred class who are always
to be found ready in such small emergencies, were leaping aside
themselves, and pressing back the lookers on, as the poor animal
struck out his great weary limbs, endeavouring to raise himself from
the ground.
Suddenly there was a shrill cry—“The wean—look at the wean; the
brute’s fit’ll kill the wean.”
John Buchanan had pushed his way into the crowd, dragging with
him the reluctant Cuthbert—and there indeed, close to the great
hoofs of the prostrate animal, stood one of those little pale,
careworn, withered children whom one sees only in the streets of
great cities, and oftenest only at this unwholesome hour of night.
But the acuteness peculiar to the class seemed to have forsaken the
very little wrinkled old man of the Trongate. He was standing where
the next plunge would inevitably throw him down, with the strange
scared look which is not fear, common to children in great peril,
upon his small white puckered face. Again the panting horse threw
out his hoofs in another convulsive exertion. The child was down.
A shadow shot across the light. There were several cries of women.
The child was thrown into somebody’s arms uninjured. The horse
was on its feet, and a man, indistinctly seen in the midst of the
eager crowd, struggled ineffectually to raise himself from the
ground, where he had fallen.
“I am hurt a little,” said the voice of Harry Muir. “Never mind, it is
not much, I dare say. Some of you help me up.”
There was a rush to assist him; a burst of eager inquiries.
“I got a blow from the hoof; ah! I can’t tell what it is,” gasped the
young man, over whose face the pallor of deadly sickness was
stealing. He could not stand. They carried him—these rough strong
men, so gently—with his friends crowding about him, to the nearest
surgeon’s. Everybody was sympathetic; every one interested. But
Harry Muir’s head had sunk upon his breast, and the fight had gone
from his eyes. He was conscious of nothing but pain.
The accident was a serious one; his leg was broken.
CHAPTER II.
graham.