FlowPanes
和
TilePanes
是不错的布局窗格,如果您想一个接一个地连续地水平或垂直地布局子级,则可以。 它们彼此非常相似,因为它们都将子级布置成列(在水平Flow / TilePane的情况下)并按其宽度或行(在垂直Flow / TilePane的情况下)并在其高度处缠绕。
唯一的主要区别是, TilePane
将所有TilePane
放置在相同大小的图块中! 因此,将最大孩子的大小作为TilePane
中每个单独瓦片的TilePane
。 因此, TilePane
也是一种均等地调整按钮和其他控件的大小和对齐方式的好方法。 (请参阅我以前的文章《 在VBox或HBox内均等地调整按钮大小》 )
import java.util.Random;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
/**
*
* Created on: 24.03.2012
* @author Sebastian Damm
*/
public class FlowPaneAndTilePaneExample extends Application
{
private Random random;
private VBox root;
private FlowPane flowPane;
private TilePane tilePane;
@Override
public void start(Stage primaryStage) throws Exception
{
random = new Random();
root = new VBox(30);
VBox upperVBox = createUpperVBox();
VBox lowerVBox = createLowerVBox();
fillPanesWithImages();
root.getChildren().addAll(upperVBox, lowerVBox);
Scene scene = new Scene(root, 800, 600, Color.ANTIQUEWHITE);
primaryStage.setTitle("FlowPane and TilePane Example");
primaryStage.setScene(scene);
primaryStage.show();
}
private VBox createUpperVBox()
{
VBox vbox = new VBox(20);
Text textFlowPane = new Text("I am a FlowPane");
textFlowPane.setFont(Font.font("Calibri", FontWeight.BOLD, 30));
textFlowPane.setUnderline(true);
textFlowPane.setEffect(new DropShadow());
VBox.setMargin(textFlowPane, new Insets(10, 0, 0, 10));