我有一个 SegmentedButton
,它包含 3 个“仅字形”ToggleButtons
,如下所示:
<SegmentedButton maxWidth="Infinity" prefWidth="Infinity">
<buttons>
<fx:define>
<ToggleGroup fx:id="albumViewToggleGroup"/>
</fx:define>
<ToggleButton maxWidth="Infinity" fx:id="tagCloudToggle" mnemonicParsing="false" selected="true" toggleGroup="$albumViewToggleGroup">
<graphic>
<Glyph fontFamily="FontAwesome" icon="TAGS"></Glyph>
</graphic>
</ToggleButton>
<ToggleButton maxWidth="Infinity" fx:id="gridFlowToggle" mnemonicParsing="false" toggleGroup="$albumViewToggleGroup" >
<graphic>
<Glyph fontFamily="FontAwesome" icon="TH"></Glyph>
</graphic>
</ToggleButton>
<ToggleButton maxWidth="Infinity" fx:id="coverFlowToggle" mnemonicParsing="false" toggleGroup="$albumViewToggleGroup">
<graphic>
<Glyph fontFamily="FontAwesome" icon="ELLIPSIS_H"></Glyph>
</graphic>
<VBox.margin>
<Insets top="10.0"/>
</VBox.margin>
</ToggleButton>
</buttons>
</SegmentedButton>
SegmenedtButton 占据了整个宽度(用红线表示),但 ToggleButton 却没有。我通过设置背景颜色来检查这一点。
我希望 ToggleButton 被拉伸(stretch),以便它们每个都是 SegmentedButton 宽度的 1/3。我怎样才能做到这一点?
最佳答案
根据documentatiom可以在 fxml 绑定(bind)中使用数学运算符。
所以可以使用这样的东西:
<SegmentedButton fx:id="segButton" maxWidth="1.7976931348623157E308" >
<buttons>
<ToggleButton fx:id="option1" maxWidth="1.7976931348623157E308" prefWidth="${segButton.width / 4}" text="K3" />
<ToggleButton fx:id="option1" maxWidth="1.7976931348623157E308" prefWidth="${segButton.width / 4}" text="K2" />
<ToggleButton fx:id="option1" maxWidth="1.7976931348623157E308" prefWidth="${segButton.width / 4}" text="K1" />
<ToggleButton fx:id="option1" maxWidth="1.7976931348623157E308" prefWidth="${segButton.width / 4}" text="K1,1" />
</buttons>
</SegmentedButton>
可能不再需要,但希望对最终使用 google 搜索此内容的任何人有用。
关于JavaFX SegmentedButton - 全宽按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31155547/