javafxhbox移动元素

javafxhbox移动元素,javafx,Javafx,明白了吗 package net.makerimages.starling.src.window; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Button;

明白了吗

  package net.makerimages.starling.src.window;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import net.makerimages.starling.src.Main;

 /**
 * Created with IntelliJ IDEA.
 * User: Kodukas
 * Date: 29.11.13
 * Time: 23:53
 * To change this template use File | Settings | File Templates.
 */
public class TopBar extends HBox
{
public Button closeButton;
public Button minMaxButton;
public Label titleLabel;

public TopBar()
{
    titleLabel=new Label("Starling browser");
    closeButton=new Button("X");

    closeButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent actionEvent) {
            Platform.exit();
        }
    });
    closeButton.setStyle("-fx-opacity: 0.9;");

    minMaxButton=new Button("|  |");
    minMaxButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent actionEvent) {

            if(Main.stg.isFullScreen()==false)
            {
                 Main.stg.setFullScreen(true);
                minMaxButton.setText("||");
            }
            else if(Main.stg.isFullScreen()==true)
            {
                Main.stg.setFullScreen(false);
                minMaxButton.setText("|  |");
                Main.browser.setMaxHeight(Main.browser.getHeight()-20);
            }
        }
    });



    this.getChildren().addAll(closeButton,minMaxButton);
    this.getChildren().add(titleLabel);
    setMargin(titleLabel,new Insets(0,10,0,0));


}
}
package net.makerimages.starling.src.window;
导入javafx.application.Platform;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.geometry.Insets;
导入javafx.geometry.Pos;
导入javafx.scene.control.Button;
导入javafx.scene.control.Label;
导入javafx.scene.layout.HBox;
导入javafx.scene.layout.Priority;
导入net.makerimages.starling.src.Main;
/**
*使用IntelliJ IDEA创建。
*用户:Kodukas
*日期:29.11.13
*时间:23:53
*要更改此模板,请使用文件|设置|文件模板。
*/
公共类TopBar扩展了HBox
{
公共按钮关闭按钮;
公共按钮minMaxButton;
公共标签标题标签;
公共顶栏()
{
标题标签=新标签(“八哥浏览器”);
关闭按钮=新按钮(“X”);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent ActionEvent){
Platform.exit();
}
});
closeButton.setStyle(“-fx不透明度:0.9;”);
minMaxButton=新按钮(“| |”);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent ActionEvent){
if(Main.stg.isFullScreen()==false)
{
Main.stg.setFullScreen(真);
minMaxButton.setText(“| |”);
}
else if(Main.stg.isFullScreen()==true)
{
Main.stg.setFullScreen(假);
minMaxButton.setText(“| |”);
Main.browser.setMaxHeight(Main.browser.getHeight()-20);
}
}
});
this.getChildren().addAll(closeButton、minMaxButton);
this.getChildren().add(titleLabel);
setMargin(标题标签,新插图(0,10,0,0));
}
}
我想要的是右边的按钮和中间的标签,但是我尝试过的任何东西都不起作用。(这是边框窗格中的工具栏)
我尝试了我所知道的一切

使用
StackPane
作为工具栏的基本容器。将
标签
HBox
添加到堆栈窗格。标签将自动与中心对齐。将按钮添加到HBox;在HBox上,将对齐属性设置为
TOP\u RIGHT
。根据需要设置填充、间距等


使用SceneBuilder来试验这样的布局非常有用。

我建议使用
网格窗格
并将元素添加到它们需要的行和列中