目录
一、面板类
(1)Pane面板
package com.javafx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Panex extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Circle circle=new Circle(25, Color.LIGHTCORAL);
circle.setCenterX(100);
circle.setCenterY(50);
Rectangle rectangle=new Rectangle(100,40,Color.LIGHTBLUE);
rectangle.relocate(100,50);
//旋转
rectangle.setRotate(-33);
Pane pane=new Pane(circle,rectangle);
// pane.getChildren().addAll(circle, rectangle);
Scene scene=new Scene(pane,300,200);
primaryStage.setTitle("面板图形");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
(2)HBox面板
实现水平排列的控件框
package com.javafx;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.scene.control.Button;
public class HBox2 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button button1=new Button("确定");
Button button2=new Button("取消");
//设置按钮大小
button1.setPrefSize(200,20);
button2.setPrefSize(100,20);
HBox hBox=new HBox(button1,button2);
//水平框中内容与边界之间的距离(上、右、下、左)
hBox.setPadding(new Insets(15,12,15,12));
//水平框中控件之间的距离
hBox.setSpacing(10);
Scene scene=new Scene(hBox,300,50);
primaryStage.setTitle("HBxo");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
(3)VBox面板
实现垂直排列的控件框
package com.javafx;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class VBox2 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button red=new Button("红色");
Button green=new Button("绿色");
Button blue=new Button("蓝色");
Button yellow=new Button("黄色");
blue.setPrefSize(100,20);
VBox vBox=new VBox(red,green,blue,yellow);
//设置控制框居中对齐
vBox.setAlignment(Pos.CENTER);
//垂直框之间的距离
vBox.setSpacing(20);
Scene scene=new Scene(vBox,300,200);
primaryStage.setTitle("