代码之家  ›  专栏  ›  技术社区  ›  SedJ601

JavaFx TextArea提示文本

  •  2
  • SedJ601  · 技术社区  · 6 年前

    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 回复  |  直到 6 年前
        1
  •  2
  •   Guest 21    6 年前

    您可以尝试使用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