文本对齐是对齐但向右

时间:2018-05-13 19:20:35

标签: css javafx fxml text-alignment richtextfx

我们希望文本对齐方式拉伸线条并使宽度相等,但是从InlineCssTextArea(来自RichTextFX)的右侧开始。

我用过:

-fx-text-alignment:justify;

The result

Required

我还需要做些什么呢?

2 个答案:

答案 0 :(得分:2)

这是一个带有结果输出的可运行示例我想通过将节点方向设置为从右到左来完成此操作

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.NodeOrientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.fxmisc.richtext.InlineCssTextArea;

public class Main extends Application {

    @Override
    public void start(Stage stage) {
        InlineCssTextArea inlineCssTextArea = new InlineCssTextArea();
        inlineCssTextArea.setMinHeight(200);
        inlineCssTextArea.setPadding(new Insets(20, 20, 20,20));
        inlineCssTextArea.setWrapText(true);
        inlineCssTextArea.appendText("Lorem ipsum dolor sit amet, veritus volumus sapientem ad pri, his delicata" +
                " splendide eu, nostrum intellegat liberavisse ei duo. Quaeque bonorum ex pri, et usu dicant oportere" +
                " qualisque. Suscipit deseruisse philosophia te mel. Pro ad assum intellegat, at vel sumo percipitur," +
                " nam principes dissentias persequeris eu. Oratio singulis gloriatur eum te," +
                " elitr soluta molestie nec an.");

        //The next line is what you need
        inlineCssTextArea.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);


        VBox vBox = new VBox(inlineCssTextArea);
        vBox.setAlignment(Pos.CENTER);

        Scene scene = new Scene(vBox);

        stage.setWidth(500);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) { launch(args); }
}

答案 1 :(得分:0)

你想要这样的东西吗?

.text-justify-right {
text-align: justify;
direction:rtl;
}
<div class="text-justify-right">text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text .</div>