如何在 Java FX 工具栏中右对齐按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24896498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to right align a button in Java FX toolbar
提问by Japheth Ongeri - inkalimeva
I am building a UI using Java FX scene builder and I want a button in a toolbar to float towards the right side of the toolbar. I have tried changing the node orientation of the parent(toolbar) and also the button but both seem to be ignored.
我正在使用 Java FX 场景构建器构建 UI,我希望工具栏中的按钮浮动到工具栏的右侧。我曾尝试更改父(工具栏)和按钮的节点方向,但似乎都被忽略了。
采纳答案by jewelsea
Add a pane with no content which always grows to fit available space between the left aligned tools in the bar and right aligned ones.
添加一个没有内容的窗格,该窗格始终增长以适应栏中左对齐工具和右对齐工具之间的可用空间。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<ToolBar prefHeight="40.0" prefWidth="318.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<Button text="Apples" />
<Button text="Oranges" />
<Pane HBox.hgrow="ALWAYS" />
<Button text="Help" />
</ToolBar>
回答by sushmitha shenoy
If you could place ur button inside a stack pane then u could make use of Stackpane's alignment property that takes javafx.geometry.Pos - The alignment of the child within the stackpane.For example in ur case:
如果您可以将您的按钮放在堆栈窗格中,那么您可以利用 Stackpane 的对齐属性,该属性采用 javafx.geometry.Pos - 堆栈窗格内子项的对齐方式。例如在您的情况下:
<StackPane >
<Button translateY="-15" translateX="15" StackPane.alignment="TOP_RIGHT"/>
</StackPane>
回答by YALCIN
BorderPane mainBorderPane = new BorderPane();
BorderPane ToolBorderPane = new BorderPane();
ToolBar tBarLeft=new ToolBar();
ToolBar tBarRight=new ToolBar();
ToolBorderPane.setLeft(tBarLeft);
ToolBorderPane.setRight(tBarRight);
mainBorderPane.setTop(ToolBorderPane);
... ... for your left aligment items add tBarLeft and your right aligment items add tBarRight
... ...为您的左对齐项目添加 tBarLeft 和您的右对齐项目添加 tBarRight