import java.util.List; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.layout.VBox; import javafx.scene.Scene; import javafx.scene.control.ComboBox; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; public class FontNameSizeApp extends Application { static final String multilingual = "(Latin) English français Deutsch \n" + "Português italiano svenska español\n" + "(zh) \u7b80\u4f53\u4e2d\u6587\n" + "(zt) \u7e41\u9ad4\u4e2d\u6587\n" + "(ja) \u65e5\u672c\u8a9e\n" + "(ko) \ud55c\uad6d\uc778\n" + "(th) \u0e17\u0e2d\u0e1c\u0e49\u0e32\u0e44\u0e2b\u0e21\u0e0a\u0e38\u0e14\u0e19\u0e2d\u0e19\u0e41\u0e25\u0e01\u0e1c\u0e25\u0e36\u0e01\u0e2a\u0e35\u0e1f\u0e49\u0e32?\n" + "(hi) \u0928\u0940\u0932\u0947 \u0915\u094D\u0935\u093E\u0930\u094D\u091F\u094D\u091C \u0915\u0947 \u0932\u093F\u090F \u0935\u093F\u092E\u0930\u094D\u0936 \u0930\u0947\u0936\u092E \u092A\u091C\u093E\u092E\u093E \u092C\u0941\u0928\u093E? \n" + "(he) \u05e4\u05d9\u05d2\u05de\u05ea \u05de\u05e9\u05d9 \u05d0\u05e8\u05d5\u05d2 \u05d4\u05d7\u05dc\u05d9\u05e4\u05d4 \u05dc\u05e7\u05d5\u05d5\u05e8\u05e5 \u05d4\u05db\u05d7\u05d5\u05dc?\n" + "(ar) \u0645\u0646\u0627\u0645\u0629 \u0627\u0644\u062d\u0631\u064a\u0631 \u0627\u0644\u0645\u0646\u0633\u0648\u062c\u0629 \u0644\u062a\u0628\u0627\u062f\u0644 \u0627\u0644\u0643\u0648\u0627\u0631\u062a\u0632 \u0627\u0644\u0623\u0632\u0631\u0642\u061f\n"; ComboBox fontNameCB, fontSizeCB; Text text; double fontSize = 10.0; String fontName = "System Regular"; private void init(Stage primaryStage) { VBox root = new VBox(); Scene scene = new Scene(root, 600, 800); primaryStage.setScene(scene); text = new Text(multilingual); fontNameCB = new ComboBox(); List fontNames = Font.getFontNames(); for (int i = 0; i < fontNames.size(); i++) { fontNameCB.getItems().add(fontNames.get(i)); } fontNameCB.getSelectionModel().select(fontName); fontNameCB.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { public void changed(ObservableValue ov, Object t, Object t1) { fontName = (String) fontNameCB.getSelectionModel().getSelectedItem(); text.setFont(new Font(fontName, fontSize)); System.out.println("Logical Font=[" + text.getFont().getFamily() + "] real font=[" + ((com.sun.javafx.font.CompositeFontResource)((com.sun.javafx.font.PGFont)text.getFont().impl_getNativeFont()).getFontResource()).getSlotResource(0).getFullName()+']'); } }); fontSizeCB = new ComboBox(); for (int i = 2; i <= 72; i +=1) { fontSizeCB.getItems().add(i); } fontSizeCB.getSelectionModel().select("10"); fontSizeCB.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { public void changed(ObservableValue ov, Object t, Object t1) { int size = (int) fontSizeCB.getSelectionModel().getSelectedIndex() + 2; fontSize = size; text.setFont(new Font(fontName, fontSize)); } }); text.setFont(new Font(fontName, fontSize)); root.getChildren().addAll(fontNameCB, fontSizeCB, text); } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); String prismText = (System.getProperty("prism.text") == null) ? "prism.order is not set" : System.getProperty("prism.text"); primaryStage.setTitle(System.getProperty("javafx.runtime.version") + "-" + prismText); primaryStage.show(); } public static void main(String[] args) { launch(args); } }