Forum Stats

  • 3,853,608 Users
  • 2,264,246 Discussions


Aligning transformed Text (and other shapes) inside StackFrame

NikolayArtamonov Member Posts: 3
edited Sep 22, 2013 3:50PM in JavaFX 2.0 and Later

Good day, guys! I have StackPane and scaled (enlarged with scaleX and scaleY properties) Text node inside pane. When text aligned to center of pane (Pic. 1) there are no issues. But when I try to align to left, right, or any other sides or corners then text positioned outside of pane (Pic. 2). How can I fix it? Text have TextBoundsType.VISUAL bounds. Thanks!

Link to image...

Pic. 1. Grey text aligned to center of stack pane.


Link to image...

Pic. 2. Grey text aligned to left side of stack pane.



Best Answer

  • MoC
    MoC Member Posts: 48

    You could try wrapping the Text in a Group. I tested in Scene Builder and it seemed to work ok with different StackPane alignments:

    <?xml version="1.0" encoding="UTF-8"?>
    <?import java.lang.*?>
    <?import java.util.*?>
    <?import javafx.scene.*?>
    <?import javafx.scene.layout.*?>
    <?import javafx.scene.paint.*?>
    <?import javafx.scene.text.*?>
    <StackPane alignment="TOP_LEFT" prefHeight="230.0" prefWidth="335.0" style="" xmlns:fx="" xmlns="">
        <Group id="Group">
            <Text layoutX="-29.0" layoutY="-11.0" scaleX="2.0" scaleY="2.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" />


This discussion has been closed.