如何在JavaFX中将工具栏的项目对齐到右侧 [英] How can I align items of Toolbar to the right in JavaFX

查看:1429
本文介绍了如何在JavaFX中将工具栏的项目对齐到右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将工具栏中的项目对齐?
所有对齐设置似乎都不起作用。

How can I align the items of a toolbar to the right?? All alignment settings seem to not work.

我正在使用布局设计器。

I´m using the layout designer.

请帮助

<BorderPane fx:controller="vmanager.ui.Controller" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
        prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<top>
    <ToolBar prefWidth="200.0" BorderPane.alignment="CENTER_RIGHT">
        <items>
            <Button alignment="CENTER_RIGHT" mnemonicParsing="false" text="_"/>
            <Button mnemonicParsing="false"/>
            <Button mnemonicParsing="false" text="X" onAction="#close"/>
        </items>
    </ToolBar>
</top>

推荐答案

这可以使用 AnchorPane 而不是工具栏:

This is doable with an AnchorPane instead of the toolbar:

<BorderPane id="BorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
  <top>
    <AnchorPane prefHeight="50.0">
      <children>
        <Button layoutY="14.0" mnemonicParsing="false" text="Button" AnchorPane.rightAnchor="14.0" />
        <Button layoutY="15.0" mnemonicParsing="false" text="Button" AnchorPane.rightAnchor="70.0" />
        <Label layoutY="18.0" prefWidth="449.0" text="Label" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="140.0" />
      </children>
    </AnchorPane>
  </top>
</BorderPane>

我还添加了窗口标题标签。您可以设置 AnchorPane 的样式,但是如果这样可以达到您想要的布局行为,那么您可以使用它。

I also added the "window title" label. You can style the AnchorPane however you like later, if this achieves your desired layout behaviour.

这篇关于如何在JavaFX中将工具栏的项目对齐到右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆