如何在JavaFx中显示按钮中的所有文本

如何在JavaFx中显示按钮中的所有文本,java,javafx,Java,Javafx,因此,我尝试在JavaFX中显示所有文本,它应该显示字体中的所有文本: 这是我的javafx代码 <HBox> <GridPane xmlns:fx= "http://javafx.com/fxml" hgap = "10" vgap = "0"> <Button text = "Explore Catalogue" alignment = "center" styleClass = "largeButton" GridPane.columnIndex="0"

因此,我尝试在JavaFX中显示所有文本,它应该显示字体中的所有文本: 这是我的javafx代码

<HBox> 
<GridPane xmlns:fx= "http://javafx.com/fxml" hgap = "10" vgap = "0">

<Button text = "Explore Catalogue" alignment = "center" styleClass = "largeButton" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<Button text = "Customer Record" styleClass = "largeButton" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<Button text = "Top-up Account" styleClass = "largeButton" GridPane.columnIndex="2" GridPane.rowIndex="2"/>
<Button text = "Favourite Movies" styleClass = "largeButton" GridPane.columnIndex="3" GridPane.rowIndex="2"/>



</GridPane>

}通过添加
-fx wrap text:true
在css样式表中,它会起作用。此css属性继承自标记为的
,并允许巧妙地包装文本(首先是空格)

编辑

这也可以通过使用
myLargeButton.setWrapText(true)
编写代码来完成,或者通过添加
wrapText=“true”
将其直接添加到FXML文件中,这将为您提供:

<Button text = "Favourite Movies" wrapText="true" styleClass = "largeButton" GridPane.columnIndex="3" GridPane.rowIndex="2"/>

但是为了清晰起见,这里建议您使用css样式表进行此操作,这也是因为您已经有了css样式表。

尝试将
wrapText=“true”
添加到按钮中,如


或者检查此处:

您是否尝试了
-fx wrap text:true
.largeButton {
    -fx-font-family: "Verdana";
    -fx-pref-width: 200px;
    -fx-pref-height: 200px;
    -fx-font-size: 28px;
    -fx-background-color: white;
    -fx-text-fill: #4d4b44;
    -fx-border-color: #dedede;
    -fx-wrap-text : true;
}
<Button text = "Favourite Movies" wrapText="true" styleClass = "largeButton" GridPane.columnIndex="3" GridPane.rowIndex="2"/>