Java Reference
In-Depth Information
Font
One final topic is font. The easiest way to create a font is to use a
javafx.scene
.text.Font
object literal giving it a size and a font name.
var font = Font { name: "Lucida Grande Bold" size: 36 };
font: Font { name: "Arial" size: 24 }
font: Font { name: "Arial Bold" size: 12 }
font: Font { name: "Book Antiqua Bold Italic" size: 14}
var defaultFont = Font {};
The font names vary per platform and the function
Font.getFontNames()
retrieves the set of available names in the form of a sequence of string.
Programmer Tip:
With JDK 1.6, it is possible to programmatically install your
own font. However, for JavaFX to know about these fonts, you need to register them
with Java before the first JavaFX font is created. Here is an example code fragment:
var fontResource = "{__DIR__)myFont.ttf";
var fontDef = fontRes.getClass().getResourceAsStream(fontRes);
var awtFont: java.awt.Font = if(fontDef != null) {
java.awt.Font.creatFont(
java.awt.Font.TRUETYPE_FONT, fontDef
);
} else {
null;
};
if(awtFont != null) {
// this requires JRE 1.6
GraphicsEnvironment.getLocalGraphicsEnvironment().
registerFont(awtFont);
}
This only works with True Type Fonts and only works with JDK 1.6. The other
option is to install the font into the JRE lib/fonts directory.
The
javafx.scene.control.TextBox
class provides a means for user text input
and editing. An example of a
TextBox
is shown in Figure 5.22.
A
TextBox
can be editable or not using the
editable
Boolean variable and you
can specify the number of columns with the
columns
variable. Also, you can
Search WWH ::
Custom Search