现场演示
->
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class LabelExample extends Application { public void start(Stage stage) { //创建标签 Label label = new Label("Sample label"); //将字体设置为标签 Font font = Font.font("Brush Script MT", FontWeight.BOLD, FontPosture.REGULAR, 25); label.setFont(font); //为标签填充颜色 label.setTextFill(Color.BROWN); //设置位置 label.setTranslateX(150); label.setTranslateY(25); Group root = new Group(); root.getChildren().add(label); //设置舞台 Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Label Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
输出结果