import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.NodeOrientation; import static javafx.scene.text.TextAlignment.*; import javafx.scene.Scene; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; import javafx.stage.Stage; public class RTLJustifyAlignment extends Application { public void start(Stage stage) { Text text1 = new Text("this is a very long sentence"); text1.setFill(Color.RED); Text text2 = new Text(" and this is the rest of it.\n"); text2.setFill(Color.BLUE); Text text3 = new Text("This is a second line of text that"); text3.setFill(Color.GREEN); Text text4 = new Text(" makes the last line wrap into another line."); text4.setFill(Color.BROWN); final TextFlow text = new TextFlow(text1, text2, text3, text4); text.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, null, null))); text.setTextAlignment(JUSTIFY); final Scene scene = new Scene(text, 200, 300); scene.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); text.prefWidthProperty().bind(scene.widthProperty()); stage.setScene(scene); stage.setTitle(System.getProperty("javafx.runtime.version")); stage.show(); } public static void main(String[] args) { launch(args); } }