How to right align a button in Java FX toolbar

ⅰ亾dé卋堺 提交于 2019-11-26 12:42:39

问题


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.


回答1:


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>



回答2:


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 >
<Button translateY="-15" translateX="15"  StackPane.alignment="TOP_RIGHT"/>
</StackPane>



回答3:


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



来源:https://stackoverflow.com/questions/24896498/how-to-right-align-a-button-in-java-fx-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!