Wednesday, June 6, 2012

Set font of text using FXML vs JavaFX

Example to set font using FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="" fx:controller="javafxml_text.Sample">

        <Text layoutX="10" layoutY="30" stroke="BLACK" text="Set Font in FXML">
                <Font name="Arial Black" size="24.0" />

Set font in FXML

Example to set font using JavaFX:

package javafx_text;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

 * @web
public class JavaFX_Text extends Application {

     * @param args the command line arguments
    public static void main(String[] args) {
    public void start(Stage primaryStage) {

        Text text = new Text();
        text.setText("Text Font in JavaFX");
        text.setFont(Font.font("Arial Black", 24.0));

        StackPane root = new StackPane();
        Scene scene = new Scene(root, 300, 250);

Set font in JavaFX

1 comment:

  1. you can show how to add a custom font for javafx?