java swing 网格布局 java显示网格_intellij-idea


package com.example.javafxproject;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class Cell extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        Scene scene = new Scene(getPane(), 300, 250);
        primaryStage.setScene(scene);
        primaryStage.setTitle("饼图");
        primaryStage.show();
    }

    private Pane getPane() {
        Pane pane = new Pane();

        Line left = new Line(10, 10, 10, 10);  //左线
        left.setStyle("-fx-fill: red; -fx-stroke-width: 5px;");
        left.startXProperty().bind(pane.widthProperty().multiply(0.30));
        left.endXProperty().bind(pane.widthProperty().multiply(0.30));
        left.endYProperty().bind(pane.heightProperty().subtract(10));

        Line right = new Line(10, 10, 10, 10);  //右线
        right.setStyle("-fx-fill: red; -fx-stroke-width: 5px;");
        right.startXProperty().bind(pane.widthProperty().multiply(0.70));
        right.endXProperty().bind(pane.widthProperty().multiply(0.70));
        right.endYProperty().bind(pane.heightProperty().subtract(10));

        Line up = new Line(10, 10, 10, 10); //上线
        up.setStyle("-fx-fill: blue; -fx-stroke-width: 5px;");
        up.startYProperty().bind(pane.heightProperty().multiply(0.30));
        up.endXProperty().bind(pane.widthProperty().subtract(10));
        up.endYProperty().bind(pane.heightProperty().multiply(0.30));

        Line down = new Line(10, 10, 10, 10);   //下线
        down.setStyle("-fx-fill: blue; -fx-stroke-width: 5px;");
        down.startYProperty().bind(pane.heightProperty().multiply(0.70));
        down.endXProperty().bind(pane.widthProperty().subtract(10));
        down.endYProperty().bind(pane.heightProperty().multiply(0.70));

        pane.getChildren().addAll(left, right, up, down);
        return pane;
    }
}

java swing 网格布局 java显示网格_饼图_02