import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.application.Launcher; import javafx.geometry.Bounds; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.Text; import javafx.scene.text.TextBoundsType; import javafx.stage.Stage; import javafx.util.Duration; /** * * @author Thor Johannesson */ public class BadJRT8268 extends Application { @Override public void start(Stage stage) { String content = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String numberContent = "0123456789`~!@#$%^&*()_+-=[]{}\\|;':\",./<>?"; stage = new Stage(); Group group = new Group(); Scene scene = new Scene(group, 1024, 768); stage.setScene(scene); Text text; Text textJFX = new Text(50, 550, "JavaFX"); // Enable VISUAL bounds will eliminate dirty region //textJFX.setBoundsType(TextBoundsType.VISUAL); textJFX.setFont(Font.font("Lucida Sans", 50)); Bounds tParentBounds = textJFX.getBoundsInParent(); Bounds tLogicalBounds = textJFX.getBoundsInLocal(); double x = tLogicalBounds.getMinX(); double y = tLogicalBounds.getMinY(); double width = tLogicalBounds.getWidth(); double height = tLogicalBounds.getHeight(); width = tParentBounds.getWidth(); height = tParentBounds.getHeight(); Rectangle rect = new Rectangle(x, y, width, height); rect.setFill(null); rect.setStroke(Color.RED); group.getChildren().addAll(textJFX,rect); Rectangle rect2; content = content + content.toLowerCase() + numberContent; double dx = 60.0, dy = 70.0; final int NUM_COLUMNS = 15; for (int i = 0; i < content.length(); i++) { x = (i % NUM_COLUMNS) * dx + 5.0; y = (i / NUM_COLUMNS) * dy + 60.0; text = new Text(x, y,content.substring(i, i+1)); //text.setFont(new Font(50)); // Times New Roman Italic exaggerates problem text.setFont( Font.font("Times New Roman", FontPosture.ITALIC, 50)); //text.setFont( Font.font("Lucida Sans", FontPosture.REGULAR, 50)); tLogicalBounds = text.getBoundsInLocal(); x = tLogicalBounds.getMinX(); y = tLogicalBounds.getMinY(); width = tLogicalBounds.getWidth(); height = tLogicalBounds.getHeight(); rect = new Rectangle(x, y, width, height); rect.setFill(null); rect.setStroke(Color.RED); text.setBoundsType(TextBoundsType.VISUAL); tParentBounds = text.getBoundsInParent(); x = tParentBounds.getMinX(); y = tParentBounds.getMinY(); width = tParentBounds.getWidth(); height = tParentBounds.getHeight(); rect2 = new Rectangle(x, y, width, height); rect2.setFill(null); rect2.setStroke(Color.BLUE); group.getChildren().addAll(text, rect, rect2); } stage.setVisible(true); //Animiating "JavaFX" final Timeline timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); final KeyValue kv = KeyValue.keyValue(textJFX.xProperty(), 200); final KeyFrame kf = new KeyFrame(Duration.valueOf(500), kv); timeline.getKeyFrames().add(kf); timeline.play(); } public static void main(String args[]) { Launcher.launch(BadJRT8268.class, args); } }