如何使用JavaFX创建标签?
现场演示
->
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);
}
}输出结果
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志