我試圖在左上角的這 3 個按鈕上顯示一些文本,但不知何故這是不可能的......
這是影像,因此您可以看到按鈕的位置:

我已經嘗試過的:
- 添加 wraptext="true"
- 設定 textOverrun="CLIP" 但這兩種情況都不起作用!
這是 FXML 片段:
<HBox fx:id="buttons_group" alignment="CENTER_LEFT" prefHeight="22.0" spacing="7" style="-fx-padding: 0 0 0 8" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.5" AnchorPane.topAnchor="0.0">
<Button fx:id="closebtn" text="×" textFill="black" onm ouseClicked="#onClickCloseBtn" style="-fx-background-radius: 50; -fx-min-height: 9; -fx-min-width: 9; -fx-max-height: 9; -fx-max-width: 9; -fx-background-color: #FF453A" />
<Button fx:id="minimizebtn" text="-" textFill="black" onm ouseClicked="#onClickMinimizeBtn" style="-fx-background-radius: 50; -fx-min-height: 9; -fx-min-width: 9; -fx-max-height: 9; -fx-max-width: 9; -fx-background-color: #FFD60A" />
<Button fx:id="maximizebtn" text="□" textFill="black" onm ouseClicked="#onClickMaximizeBtn" style="-fx-background-radius: 50; -fx-min-height: 9; -fx-min-width: 9; -fx-max-height: 9; -fx-max-width: 9; -fx-background-color: #32D74B" />
</HBox
謝謝!
uj5u.com熱心網友回復:
為您的按鈕設定負填充。
您可能還想減小字體大小,因為默認值為 12 像素,而您的按鈕大小為 9 像素。
但是,對于這么小的按鈕,居中并不完美……
這是在 SceneBuilder 中完成的示例。
<HBox alignment="CENTER_LEFT" prefHeight="22.0" spacing="7.0" style="-fx-background-color: #333;">
<children>
<Button maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="9.0" prefWidth="9.0" style="-fx-background-radius: 4.5; -fx-background-color: #FF453A; -fx-padding: -100;" text="x">
<font>
<Font size="10.0" />
</font>
</Button>
<Button maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="9.0" prefWidth="9.0" style="-fx-background-radius: 4.5; -fx-background-color: #FFD60A; -fx-padding: -100;" text="-">
<font>
<Font size="10.0" />
</font>
</Button>
<Button maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="9.0" prefWidth="9.0" style="-fx-background-radius: 4.5; -fx-background-color: #32D74B; -fx-padding: -100;" text="□">
<font>
<Font size="10.0" />
</font>
</Button>
</children>
<padding>
<Insets bottom="7.0" left="7.0" right="7.0" top="7.0" />
</padding>
</HBox>
結果 :
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/448716.html
