package jira; import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.NodeOrientation; import static javafx.geometry.NodeOrientation.*; import static javafx.scene.text.TextAlignment.*; import javafx.scene.Scene; import javafx.scene.input.KeyEvent; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import javafx.scene.text.TextFlow; import javafx.stage.Stage; public class RT27541 extends Application { public void start(Stage stage) { // final Text text = new Text("\u05d1\u05d2\u05d3\u05d4 ABC."); 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))); final Scene scene = new Scene(text, 200, 400); text.prefWidthProperty().bind(scene.widthProperty()); scene.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler () { @Override public void handle(KeyEvent event) { if (event.getCharacter().equals("1")) { TextAlignment align = text.getTextAlignment(); if (align == LEFT) text.setTextAlignment(CENTER); if (align == CENTER) text.setTextAlignment(RIGHT); if (align == RIGHT) text.setTextAlignment(JUSTIFY); if (align == JUSTIFY) text.setTextAlignment(LEFT); System.out.println(text.getTextAlignment()); } if (event.getCharacter().equals("2")) { NodeOrientation o = text.getNodeOrientation(); if (o == INHERIT) text.setNodeOrientation(LEFT_TO_RIGHT); if (o == LEFT_TO_RIGHT) text.setNodeOrientation(RIGHT_TO_LEFT); if (o == RIGHT_TO_LEFT) text.setNodeOrientation(LEFT_TO_RIGHT); System.out.println(text.getNodeOrientation()); } } }); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }