/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ package input; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.control.TextBox; import javafx.scene.control.Slider; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.shape.Rectangle; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.Font; // for ListView test: import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; /** * * @author shubov */ public class TestTextApp extends Application { private static final String INITIAL_TEXT = "JavaFX"; final Text testText = new Text(); @Override public void start(Stage stage) { VBox buttonList = new VBox(5); // placeholder for text testing Rectangle testfieldRect = new Rectangle(); testfieldRect.setHeight(400); testfieldRect.setWidth(500); testfieldRect.setX(10); testfieldRect.setY(10); testfieldRect.setStroke(Color.TRANSPARENT); testfieldRect.setStrokeWidth(2f); testfieldRect.setFill(Color.TRANSPARENT); HBox hBox = new HBox(5); // test text position and initial attributes testText.setX(100); testText.setY(200); testText.setFill(Color.BLUE); testText.setStroke(Color.RED); // TEXT INPUT hBox = new HBox(5); final Text labelInputField = new Text("test string:"); final TextBox textBox = new TextBox(INITIAL_TEXT); testText.textProperty().bind(textBox.textProperty()); hBox.getChildren().add(labelInputField); hBox.getChildren().add(textBox); buttonList.getChildren().add(hBox); // FONT SIZE hBox = new HBox(5); final Text textFontSize = new Text("Font Size"); final Slider slider1 = new Slider(10, 240, 22); slider1.valueProperty().addListener(new ChangeListener() { public void changed(ObservableValue ov, Number t, Number t1) { testText.setFont(new Font(testText.getFont().getName(), t.doubleValue())); } }); hBox.getChildren().add(textFontSize); hBox.getChildren().add(slider1); buttonList.getChildren().add(hBox); Group root = new Group(); stage.setScene(new Scene(root)); root.getChildren().add(testText); VBox vb1 = new VBox(); vb1.getChildren().add(testfieldRect); vb1.getChildren().add(buttonList); root.getChildren().add(vb1); stage.setVisible(true); } public static void main(String[] args) { launch(args); } }