developers

    Forum Stats

  • 3,873,719 Users
  • 2,266,633 Discussions
  • 7,911,614 Comments

Discussions

Aligning transformed Text (and other shapes) inside StackFrame

NikolayArtamonov
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.

StackPane.setAlignment(Pos.CENTER)

Link to image...

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

StackPane.setAlignment(Pos.CENTER_LEFT)

Tagged:

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="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
      <children>
        <Group id="Group">
          <children>
            <Text layoutX="-29.0" layoutY="-11.0" scaleX="2.0" scaleY="2.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" />
          </children>
        </Group>
      </children>
    </StackPane>
    

Answers

This discussion has been closed.
developers