如何使用JavaFX中的文本流向文本添加各种字体?
现场演示
->
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
public class TextFlowExample extends Application {
public void start(Stage stage) throws FileNotFoundException {
//创建一个文本对象
String str1 = "Hi ";
Text text1 = new Text(30.0, 110.0, str1);
//设置字体
Font font1 = Font.font("Brush Script MT", FontWeight.BOLD, 75);
text1.setFont(font1);
//设置文字的颜色
text1.setFill(Color.CORAL);
text1.setStrokeWidth(1);
text1.setStroke(Color.CHOCOLATE);
String str2 = "Welcome To";
Text text2 = new Text(40.0, 110.0, str2);
Font font2 = Font.font("Verdana", FontWeight.LIGHT, 25);
text2.setFont(font2);
//设置文字的颜色
text2.setFill(Color.YELLOWGREEN);
text2.setStrokeWidth(1);
text2.setStroke(Color.DARKRED);
String str3 = "Nhooo";
Text text3= new Text(50.0, 110.0, str3);
Font font3 = Font.font("Kunstler Script", FontWeight.BOLD, 80);
text3.setFont(font3);
//设置文字的颜色
text3.setFill(Color.CORNFLOWERBLUE);
text3.setStrokeWidth(1);
text3.setStroke(Color.CRIMSON);
//创建文本流
TextFlow textFlow = new TextFlow();
textFlow.getChildren().addAll(text1, text2, text3);
//设置舞台
Group root = new Group(textFlow);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Text Flow Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下