【发布时间】:2018-10-08 13:48:46
【问题描述】:
我想将 Button 与 TextField 交换。怎么做?
听说有 toFront() 和 toBack() 方法。但是子节点必须包装在一个组中。这是真的吗?
还有其他方法吗?
<ToolBar fx:id="toolbarForActivityPanel" layoutX="22.0" layoutY="316.0" prefHeight="0.0" prefWidth="518.0" style="-fx-background-color: black;" AnchorPane.bottomAnchor="21.0" AnchorPane.leftAnchor="21.0" AnchorPane.rightAnchor="21.0">
<items>
<Button fx:id="createOfActivityButton" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="46.0" prefWidth="48.0" style="-fx-background-color: black; -fx-border-color: white; -fx-border-insets: 0px 10px 0px 0px;">
<graphic>
<ImageView fitHeight="30.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" style="-fx-background-color: black; -fx-border-radius: 4px;">
<image>
<Image url="@../../img/icons_of_activities/icons8-plus-math-48.png" />
</image>
</ImageView>
</graphic>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Button>
<Button mnemonicParsing="false" prefHeight="46.0" prefWidth="48.0" style="-fx-background-color: black; -fx-border-color: white; -fx-border-insets: 0 10 0 0;">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<graphic>
<ImageView fitHeight="30.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" style="-fx-background-color: black; -fx-border-radius: 4px;">
<image>
<Image url="@../../img/icons_of_activities/icons8-search-filled-50.png" />
</image>
</ImageView>
</graphic>
</Button>
<TextField />
</items>
</ToolBar>
【问题讨论】:
-
您能否澄清一下:您是否打算在某个时候以编程方式切换它们(例如,作为对用户操作的响应)?还是您只是希望它们以不同的顺序开始?
-
当您单击加号按钮时,TextField 会出现在按钮的左侧。
-
理想情况下,我希望在单击按钮时,将此按钮替换为另一个节点 - TextField