設置佈局內各個UI組件對齊填充間距方式
1.對齊填充間距概述
Padding:填充-子控件與父級的間距
Spacing:間距-各個子控件之間的間距
Alignment:對齊-上下左右對齊方式
2. 對齊填充Demo
package javafxdemo;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
import javax.xml.soap.Text;
/**
* @author bruce
*
*/
public class PaddingDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
HBox hBox = new HBox();
TextField textField = new TextField();
Button b1 = new Button("創建");
Button b2 = new Button("修改");
Button b3 = new Button("刪除");
Button b4 = new Button("撤銷");
hBox.getChildren().addAll(textField,b1,b2,b3,b4);
//padding設置子控件與父級的間距
hBox.setPadding(new Insets(10,2,30,40));
//Spacing設置各個組件之間的間距
hBox.setSpacing(5);
//Alignment設置對齊方式
hBox.setAlignment(Pos.CENTER);
//水平增長佔滿空間
HBox.setHgrow(textField, Priority.ALWAYS);
//創建場景
Scene scene = new Scene(hBox, 700, 700);
//添加場景到窗口中
stage.setScene(scene);
//打開窗口
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}