JavaFx TextArea提示文本

时间:2018-10-10 21:59:59

标签: java javafx textarea

我正在尝试使TextArea的提示文本以某种格式显示。我可以实现所需的格式,但是它要求我在文本之间添加很多空白。我以为\n可以解决问题,但没有成功。有没有一种方法可以使提示文本在没有wrapText="true"和大量空白的情况下转到下一行?

<?xml version="1.0" encoding="UTF-8"?>

<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ez_proxy_2.toolbar_buttons.AddStanzaController">
    <children>
        <StackPane>
            <children>
                <Label alignment="CENTER" maxWidth="1.7976931348623157E308" text="Title">
                    <font>
                        <Font size="28.0" />
                    </font>
                    <padding>
                        <Insets top="10.0" />
                    </padding>
                </Label>
                <FontAwesomeIconView fx:id="faQuestionMark" glyphName="QUESTION_CIRCLE" size="32" StackPane.alignment="CENTER_RIGHT">
                    <StackPane.margin>
                        <Insets right="10.0" />
                    </StackPane.margin>
                </FontAwesomeIconView>
            </children>
        </StackPane>
        <TextField fx:id="tfTitle" alignment="CENTER" promptText="Enter Title Here">
            <VBox.margin>
                <Insets left="20.0" right="20.0" />
            </VBox.margin>
        </TextField>
        <Label alignment="CENTER" maxWidth="1.7976931348623157E308" text="Stanza Info">
            <font>
                <Font size="17.0" />
            </font>
        </Label>
        <TextArea fx:id="taStanzaInfo" promptText="Title Fake Title                                                                                                                                         URL https://www.example.com                                                                                                                     HJ www.example.com                                                                                                                               DJ example.com" wrapText="true">
            <VBox.margin>
                <Insets left="20.0" right="20.0" />
            </VBox.margin>
        </TextArea>
        <Button fx:id="btnOff" mnemonicParsing="false" onAction="#handleBtnOff" prefHeight="25.0" prefWidth="52.0" text="Off" />
        <HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0" spacing="10.0">
            <children>
                <Button fx:id="btnExit" mnemonicParsing="false" onAction="#handleBtnExit" prefHeight="25.0" prefWidth="52.0" text="Exit" />
                <Button fx:id="btnAdd" mnemonicParsing="false" onAction="#handleBtnAdd" prefHeight="25.0" prefWidth="52.0" text="Add" />
            </children>
            <VBox.margin>
                <Insets left="20.0" right="20.0" />
            </VBox.margin>
        </HBox>
    </children>
</VBox>

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以尝试将XML语法用于\r\n-&#13;&#10;(在我的测试示例中,由于某种原因,仅&#10;不能用于promptText属性,但是它可以与text一起正常工作):

<TextArea promptText="Title Fake Title&#13;&#10;URL https://www.example.com&#13;&#10;HJ www.example.com&#13;&#10;DJ example.comButton" />

enter image description here