馮斌:JavaFx實例(八)“ShowFlowPane”

   

   FlowPane將node從左到右水平或從上到下垂直放置在pane中,分別用到Orientation.HORIZONTAL和Orientation.VERTICAL方法。


   我們也可以設置node之間的距離,下面的例子演示FlowPane的用法:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class ShowFlowPane extends Application {
   @Override // Override the start method in the Application class
   public void start(Stage primaryStage) {
     // Create a pane and set its properties
     FlowPane pane = new FlowPane();
     pane.setPadding(new Insets(11,12,13,14));
     pane.setHgap(5);
     pane.setVgap(5);
     // Place nodes in the pane
     pane.getChildren().addAll(new Label("First Name:"),
     new TextField(), new Label("MI:"));
     TextField tfMi = new TextField();
     tfMi.setPrefColumnCount(1);
     pane.getChildren().addAll(tfMi, new Label("Last Name:"),new TextField());
     // Create a scene and place it in the stage
     Scene scene = new Scene(pane, 200,250);
     primaryStage.setTitle("ShowFlowPane");// Set the stage title
     primaryStage.setScene(scene);// Place the scene in the stage
     primaryStage.show();// Display the stage
   }
}


說明:

1、本代碼運行的結果如下:

wKioL1OTwCmAE2-AAAA5pvCsDsg368.jpg


2、Insets對象確定pane邊界的距離,如下圖所示:

wKioL1OTwWzAKdiWAABwpLUncwU352.jpg


3、tfMi.setPrefColumnCount(1)將MI text field優選的列數設爲1。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章