JavaFx基础之面板种类介绍

面板是容纳结点的容器,面板主要有以下几类:

1. StackPane前面已经用了,其作用就是将节点置于中央。

2.FlowPane的应用

 例子:

        import javafx.application.Application;
        import javafx.scene.Scene;
        import javafx.scene.control.Button;
        import javafx.scene.control.Label;
        import javafx.scene.control.PasswordField;
        import javafx.scene.control.TextField;
        import javafx.scene.layout.FlowPane; 


        public class FlowPaneDemo extends Application {

	    public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);

	}
	public void start(Stage primaryStage) throws Exception{
        FlowPane flowPane=new FlowPane();
        Label l1=new Label("用户");
		TextField text=new TextField("请输入你的名字");
		Label l2=new Label("用户密码");
		PasswordField ped=new PasswordField();
		Button login=new Button("登录");
		flowPane.getChildren().addAll(l1,text,l2,ped,login);
		Scene scene=new Scene(flowPane,280,200);
		primaryStage.setTitle("登录");
		primaryStage.setScene(scene);
		primaryStage.show();
}
}

3.GridPane的应用

例子:

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class GridPaneDemo extends Application  {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);

	}

	@Override
	public void start(Stage stage) throws Exception {
        GridPane pane=new GridPane();//网格矩阵结构
		pane.setAlignment(Pos.CENTER);
		pane.setPadding(new Insets(11.5,12.5,13.5,14.5));
		pane.setHgap(5.5);//设置两个结点之间的距离
		pane.setVgap(5.5);//设置两行之间的行高  
		pane.add(new Label("First Name"), 0, 0);//表示第一列,第一行;
		pane.add(new TextField(), 1, 0);
		pane.add(new Label("MI"), 0, 1);
		pane.add(new TextField(), 1, 1);
		pane.add(new Label("Last Name"), 0, 2);
		pane.add(new TextField(), 1, 2);
		Button bt=new Button("Add Name");
		pane.add(bt, 1, 3); 
		GridPane.setHalignment(bt, HPos.RIGHT);//水平向右对齐
		
		Scene scene=new Scene(pane,400,400);
		stage.setTitle("show a circle");
		stage.setScene(scene);
		stage.show();
	}

}

 5.BorderPane的应用

 6.HBox与VBox

例子:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class MulipleStage extends Application {

	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);

	}

	@Override
	public void start(Stage stage) throws Exception {
		// TODO Auto-generated method stub
		BorderPane pane=new BorderPane();
		pane.setTop(getHBox());
		pane.setLeft(getVBox());
		Scene scene=new Scene(pane,500,300);
		stage.setTitle("JavaFx");
		stage.setScene(scene);
		stage.show();
	}

         public static HBox getHBox() {
			HBox hBox=new HBox(15);
			hBox.setPadding(new Insets(15,15,15,15));
			hBox.setStyle("-fx-background-color:gray");
			hBox.getChildren().add(new Button("Computer Science"));
			hBox.getChildren().add(new Button("Chemitry"));
			hBox.getChildren().add(new Button("Math"));
			return hBox;
		}
		public static VBox getVBox() {
			VBox vBox=new VBox(15); 
			vBox.setPadding(new Insets(15,5,5,5));
			vBox.getChildren().add(new Label("Courses"));
			Label[]courses= {new Label("CSCI 1301"),new Label("CSCI 2410"),new                Label("CSCI 3720")};
			for(Label course:courses) {
				VBox.setMargin(course, new Insets(0,0,0,15));
				vBox.getChildren().add(course);
			}
			return vBox;
			
		
		
		}
		
}

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值