JavaFX如何向GridPane添加长文本-在ScrollPane中换行?怎样
我想在我的应用程序中添加长文本。当我点击POKAŻ按钮时,它会显示我的梦想字段(字符串),该字段来自名为dream的类。我有个问题。我梦想的内容很长,没有完全展示出来。当我将它包装在滚动窗格中时,它只显示一行文本 这是我的应用程序的打印屏幕 我可能会补充一点,单击POKAŻ按钮后,它会更改.fxml文件JavaFX如何向GridPane添加长文本-在ScrollPane中换行?怎样,java,xml,text,javafx,gridpane,Java,Xml,Text,Javafx,Gridpane,我想在我的应用程序中添加长文本。当我点击POKAŻ按钮时,它会显示我的梦想字段(字符串),该字段来自名为dream的类。我有个问题。我梦想的内容很长,没有完全展示出来。当我将它包装在滚动窗格中时,它只显示一行文本 这是我的应用程序的打印屏幕 我可能会补充一点,单击POKAŻ按钮后,它会更改.fxml文件 public void showMeMyDream(ActionEvent e) throws IOException { showSelectedDream();
public void showMeMyDream(ActionEvent e) throws IOException
{
showSelectedDream();
contentID.getChildren().clear(); contentID.getChildren().add(FXMLLoader.load(getClass().getResource("/fxml/showDreamFXML.fxml")));
}
以下是showDreamFXML.fxml的代码
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.VBox?>
<AnchorPane maxHeight="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller.ShowDreamController">
<children>
<VBox maxHeight="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" vgrow="ALWAYS" />
</rowConstraints>
<children>
<Label text="Label" GridPane.rowIndex="5" />
<Label fx:id="showDreamContent" text="Label" wrapText="true" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="5" GridPane.vgrow="ALWAYS" />
<Label text="Label" GridPane.rowIndex="4" />
<Label fx:id="showDreamLength" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="Label" GridPane.rowIndex="3" />
<Label fx:id="showDreamType" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="showDreamMem" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="showDreamDate" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Label" />
<Label text="Label" GridPane.rowIndex="1" />
<Label text="Label" GridPane.rowIndex="2" />
<Label fx:id="showDreamTitle" text="Label" GridPane.columnIndex="1" />
</children>
</GridPane>
<HBox>
<children>
<Button mnemonicParsing="false" text="Button" />
</children>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>
您可以使用文本而不是标签。将其放在文本流中,然后将文本流包装在滚动窗格中(如果需要),在滚动窗格上使用fitToWidth=“true”
。这样更好,但我希望滚动窗格能够动态调整大小。可能吗?我是说,我想让它像那样充满。