1
public BasicView(String name) {
        super(name);



        Button b = new Button("test test test");

        this.getChildren().addAll(b);

        width = MobileApplication.getInstance().getScreenWidth();
        height = MobileApplication.getInstance().getScreenHeight();
        VBox box = new VBox();
        box.getChildren().add(b);
        setCenter(box);

        Text t = new Text(width/4,height/2,"OMG ITS TEXT ON THE SCREEN !!!! TEST TEST TEST TEST");
        t.setWrappingWidth(100);
        this.getChildren().add(t);
        b.setOnAction(e -> this.rotate(t));
        TextFlow tf = new TextFlow();
        Text t1= new Text("This text is not bold ");
        Text t2= new Text(",this part is,");
        t2.setStyle("-fx-font-weight: bold");
        t2.setFill(Color.RED);
        Text t3= new Text("and this part is italic");
        t3.setStyle("-fx-font-style: italic");
        tf.setPrefSize(30,30);
        tf.setMaxWidth(USE_PREF_SIZE);
        tf.getChildren().addAll(t1,t2,t3);
        tf.setStyle("-fx-background-color: red");

        tf.setLayoutX(100);
        tf.setLayoutY(100);

        this.getChildren().addAll(tf);

    }

在此处输入图像描述

生成的文本流不换行并且没有背景颜色。文本的 t3 部分也不以斜体显示。我曾尝试寻找答案,但一无所获。任何帮助将不胜感激。

编辑:我忘了提到我正在使用 gluon 移动插件来使用 javaFx 构建一个 android 应用程序。

4

1 回答 1

2

Gluon 的视图从扩展BorderPane,因此您应该将 textFlow 节点添加到五个可能位置之一(即到中心)。

否则你将不得不照顾它的布局(调用resizeRelocate)。

例如,一旦将其添加到中心,它将具有适当的大小,将显示背景颜色,并将内容包裹起来。

至于斜体,Gluon Charm 使用 Roboto字体,常规、中等和粗体。如果你想要斜体样式,你需要将Roboto-Italic.ttf字体添加到你的资源(/src/main/resources/)中,然后加载它:

public BasicView(String name) {
    super(name);

    Font.loadFont(getClass()
            .getResourceAsStream("/Roboto-italic.ttf"), 10);

    TextFlow tf = new TextFlow();
    Text t1= new Text("This text is not bold ");
    Text t2= new Text(", this part is,");
    t2.setStyle("-fx-font-weight: bold");
    t2.setFill(Color.RED);
    Text t3= new Text(" and this part is italic");
    t3.setStyle("-fx-font-style: italic");
    tf.getChildren().addAll(t1,t2,t3);
    tf.setStyle("-fx-background-color: yellow");

    setCenter(tf);

}

文本流

于 2017-02-05T00:44:51.533 回答