/* * $Id$ * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ package graphics.api.text; import java.util.List; import javafx.application.Application; import javafx.application.Launcher; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.Group; import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyCode; import javafx.scene.text.*; import javafx.scene.paint.*; import javafx.collections.FXCollections; import javafx.event.EventHandler; public class JavaCrashText extends Application { public static void main(String[] args) { Launcher.launch(JavaCrashText.class, args); } int fnc = 0; Text Text_a; Text Text_b; Font myFont = new Font(); List fontNames = myFont.getFontNames(); int fontNameSize = fontNames.size(); @Override public void start(Stage stage) { double h = 400; double w = 400; if (fontNameSize == 0 || fontNames == null) { System.out.println("Quantity of fonts: " + fontNameSize + "."); return; } Text_a = new Text(0, 10, "Font Name: " + fontNames.get(fnc) + "\n(font #" + (fnc + 1) + " from " + fontNameSize + ")"); Text_a.setFont(new Font(10)); Text_a.setFill(Color.BLACK); myFont = new Font(fontNames.get(fnc), 30); Text_b = new Text(10, h / 2, "JavaFX"); Text_b.setFont(myFont); Text_b.setFill(Color.RED); //strokeWidth: 1 Text_b.setStroke(Color.BLACK); Text_b.setFocusTraversable(true); Text_b.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent e) { if (e.getCode().equals(KeyCode.VK_LEFT)) { if (fnc == fontNameSize - 1) { fnc = 0; } else { fnc++; } myFont = new Font(fontNames.get(fnc), 30); Text_b.setFont(myFont); Text_a.setContent("Font Name: " + fontNames.get(fnc) + "\n(font #" + (fnc + 1) + " from " + fontNameSize + ")"); } } }); Scene scene = new Scene(new Group(), w, h); ((javafx.scene.Group) scene.getRoot()).getChildren().clear(); ((javafx.scene.Group) scene.getRoot()).getChildren().addAll(FXCollections.observableArrayList(Text_a, Text_b)); stage.setScene(scene); stage.setVisible(true); Text_b.requestFocus(); } }