3

We want to make the text-alignment stretch the lines and make the width equal but from the right side in a InlineCssTextArea (from RichTextFX).

I have used:

-fx-text-alignment:justify;

The result

Required

Also what I need to make it work?

fabian
  • 80,457
  • 12
  • 86
  • 114
  • 3
    Well i am not familiar with RichTextFX but if its like the Text class you can do that by setting the aligment justify as you did and also set the Node Orientation from RIGHT_TO_LEFT. – JKostikiadis May 13 '18 at 19:58
  • I have not added RichTextFX to the question because I know the code for the node works well in RichTextFX, So I preferred to have the question in general, Thank you it works – Saif Al Basrawi May 13 '18 at 20:06

2 Answers2

2

Here is a runnable example with the result output you wanted I did this by setting the node orientation to right to left

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); }
}
Matt
  • 3,052
  • 1
  • 17
  • 30
  • Yes as JKostikiadis said, but the problem here is that it destroys the selection. Did you try selecting text after changing Node Orientation? – Saif Al Basrawi May 14 '18 at 15:49
0

Do you want something like this?

.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>
Kadir Bušatlić
  • 226
  • 2
  • 12