Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在网格窗格的间隙之间对齐直线?_Java_Javafx - Fatal编程技术网

Java 如何在网格窗格的间隙之间对齐直线?

Java 如何在网格窗格的间隙之间对齐直线?,java,javafx,Java,Javafx,我想知道如何在gridpane的VGap/HGap之间对齐一条线 Public class Main extends Application { private StackPane root = new StackPane(); private Scene scene = new Scene(root, 1366, 768); @Override public void start(Stage primaryStage) { GridPane

我想知道如何在gridpane的VGap/HGap之间对齐一条线

Public class Main extends Application {

    private StackPane root = new StackPane();
    private Scene scene = new Scene(root, 1366, 768);

    @Override
    public void start(Stage primaryStage) {
        GridPane gridPane = new GridPane();
        gridPane.addRow(1, new Button("0 1"), new Button("0 2"), new Button("0 3"));
        gridPane.addRow(2, new Button("1 1"), new Button("1 2"), new Button("1 3"));
        gridPane.addRow(3, new Button("2 1"), new Button("2 2"), new Button("2 3"));
        gridPane.setHgap(20);
        gridPane.setVgap(20);
        gridPane.setAlignment(Pos.CENTER);
        root.getChildren().add(gridPane);

        Separator separator = new Separator(Orientation.HORIZONTAL);
        gridPane.add(separator, 0, 1, 1, GridPane.REMAINING);

        primaryStage.setTitle("Test");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
现在我有一个网格窗格,其中的行与前缀X和Y值一起悬空,当窗口调整大小时,这些值显然是无用的。 有没有办法把一条线绑在H和V间隙的正中间


谢谢。

除了gridPane。setGridLinesVisible(true)您必须在“实”项之间的行或列中为行添加节点

例如,对于水平线,您可以这样做:

Separator separator = new Separator(Orientation.HORIZONTAL);
gridPane.add(separator, col, row, 1, GridPane.REMAINING);
以下是一个具有可调整边框大小的完整解决方案:

package example.grid;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.DoubleProperty;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;


public class Main extends Application {

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

    private Region makeVerticalLine() {
        VBox vb = new VBox();
        vb.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
        vb.setPrefHeight(1);
        vb.setPrefWidth(1);
        vb.setMaxHeight(Double.MAX_VALUE);
        return vb;
    }

    private Region makeHorizontalLine() {
        HBox hb = new HBox();
        hb.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
        hb.setPrefHeight(1);
        hb.setPrefWidth(1);
        hb.setMaxWidth(Double.MAX_VALUE);
        return hb;
    }

    private void bindWidths(DoubleProperty width, Region ... regions) {
        for (Region r : regions) {
            r.prefWidthProperty().bind(width);
        }
    }

    private void bindHeights(DoubleProperty height, Region ... regions) {
        for (Region r : regions) {
            r.prefHeightProperty().bind(height);
        }
    }

    @Override
    public void start(Stage stage) throws Exception {
        BorderPane parent = new BorderPane();
        Slider slider = new Slider(1, 100, 3);
        GridPane grid = new GridPane();
        Region h11 = makeHorizontalLine();
        Region h21 = makeHorizontalLine();
        Region h31 = makeHorizontalLine();
        Region h13 = makeHorizontalLine();
        Region h23 = makeHorizontalLine();
        Region h33 = makeHorizontalLine();
        Region h15 = makeHorizontalLine();
        Region h25 = makeHorizontalLine();
        Region h35 = makeHorizontalLine();
        Region v1 = makeVerticalLine();
        Region v2 = makeVerticalLine();

        ColumnConstraints numCol = new ColumnConstraints();
        numCol.setHalignment(HPos.CENTER);
        numCol.setHgrow(Priority.ALWAYS);
        ColumnConstraints sepCol = new ColumnConstraints();
        sepCol.setHgrow(Priority.NEVER);

        RowConstraints numRow = new RowConstraints();
        numRow.setValignment(VPos.CENTER);
        numRow.setVgrow(Priority.ALWAYS);
        RowConstraints sepRow = new RowConstraints();
        sepRow.setVgrow(Priority.NEVER);

        GridPane.setRowSpan(v1, GridPane.REMAINING);
        GridPane.setRowSpan(v2, GridPane.REMAINING);

        grid.addRow(0, new Label("7"), v1, new Label("8"), v2, new Label("9"));
        grid.add(h11,0,1);
        grid.add(h21,2,1);
        grid.add(h31,4,1);
        grid.add(new Label("4"), 0, 2);
        grid.add(new Label("5"), 2, 2);
        grid.add(new Label("6"), 4, 2);
        grid.add(h13,0,3);
        grid.add(h23,2,3);
        grid.add(h33,4,3);
        grid.add(new Label("1"), 0, 4);
        grid.add(new Label("2"), 2, 4);
        grid.add(new Label("3"), 4, 4);
        grid.add(h15,0,5);
        grid.add(h25,2,5);
        grid.add(h35,4,5);
        grid.add(new Label("0"), 2, 6);
        grid.getColumnConstraints().addAll(numCol,sepCol,numCol,sepCol,numCol);
        grid.getRowConstraints().addAll(numRow,sepRow,numRow,sepRow,numRow,sepRow,numRow);

        bindHeights(slider.valueProperty(), h11,h13,h15,h21,h23,h25,h31,h33,h35);
        bindWidths(slider.valueProperty(), v1, v2);

        VBox controls = new VBox(slider);
        parent.setTop(controls);
        parent.setCenter(grid);

        Scene scene = new Scene(parent);
        stage.setScene(scene);
        stage.show();
        Platform.setImplicitExit(true);
    }
}

除了gridPane.setGridLinesVisible(true)之外,您还必须为“实”项之间的行或列中的行添加节点

例如,对于水平线,您可以这样做:

Separator separator = new Separator(Orientation.HORIZONTAL);
gridPane.add(separator, col, row, 1, GridPane.REMAINING);
以下是一个具有可调整边框大小的完整解决方案:

package example.grid;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.DoubleProperty;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;


public class Main extends Application {

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

    private Region makeVerticalLine() {
        VBox vb = new VBox();
        vb.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
        vb.setPrefHeight(1);
        vb.setPrefWidth(1);
        vb.setMaxHeight(Double.MAX_VALUE);
        return vb;
    }

    private Region makeHorizontalLine() {
        HBox hb = new HBox();
        hb.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
        hb.setPrefHeight(1);
        hb.setPrefWidth(1);
        hb.setMaxWidth(Double.MAX_VALUE);
        return hb;
    }

    private void bindWidths(DoubleProperty width, Region ... regions) {
        for (Region r : regions) {
            r.prefWidthProperty().bind(width);
        }
    }

    private void bindHeights(DoubleProperty height, Region ... regions) {
        for (Region r : regions) {
            r.prefHeightProperty().bind(height);
        }
    }

    @Override
    public void start(Stage stage) throws Exception {
        BorderPane parent = new BorderPane();
        Slider slider = new Slider(1, 100, 3);
        GridPane grid = new GridPane();
        Region h11 = makeHorizontalLine();
        Region h21 = makeHorizontalLine();
        Region h31 = makeHorizontalLine();
        Region h13 = makeHorizontalLine();
        Region h23 = makeHorizontalLine();
        Region h33 = makeHorizontalLine();
        Region h15 = makeHorizontalLine();
        Region h25 = makeHorizontalLine();
        Region h35 = makeHorizontalLine();
        Region v1 = makeVerticalLine();
        Region v2 = makeVerticalLine();

        ColumnConstraints numCol = new ColumnConstraints();
        numCol.setHalignment(HPos.CENTER);
        numCol.setHgrow(Priority.ALWAYS);
        ColumnConstraints sepCol = new ColumnConstraints();
        sepCol.setHgrow(Priority.NEVER);

        RowConstraints numRow = new RowConstraints();
        numRow.setValignment(VPos.CENTER);
        numRow.setVgrow(Priority.ALWAYS);
        RowConstraints sepRow = new RowConstraints();
        sepRow.setVgrow(Priority.NEVER);

        GridPane.setRowSpan(v1, GridPane.REMAINING);
        GridPane.setRowSpan(v2, GridPane.REMAINING);

        grid.addRow(0, new Label("7"), v1, new Label("8"), v2, new Label("9"));
        grid.add(h11,0,1);
        grid.add(h21,2,1);
        grid.add(h31,4,1);
        grid.add(new Label("4"), 0, 2);
        grid.add(new Label("5"), 2, 2);
        grid.add(new Label("6"), 4, 2);
        grid.add(h13,0,3);
        grid.add(h23,2,3);
        grid.add(h33,4,3);
        grid.add(new Label("1"), 0, 4);
        grid.add(new Label("2"), 2, 4);
        grid.add(new Label("3"), 4, 4);
        grid.add(h15,0,5);
        grid.add(h25,2,5);
        grid.add(h35,4,5);
        grid.add(new Label("0"), 2, 6);
        grid.getColumnConstraints().addAll(numCol,sepCol,numCol,sepCol,numCol);
        grid.getRowConstraints().addAll(numRow,sepRow,numRow,sepRow,numRow,sepRow,numRow);

        bindHeights(slider.valueProperty(), h11,h13,h15,h21,h23,h25,h31,h33,h35);
        bindWidths(slider.valueProperty(), v1, v2);

        VBox controls = new VBox(slider);
        parent.setTop(controls);
        parent.setCenter(grid);

        Scene scene = new Scene(parent);
        stage.setScene(scene);
        stage.show();
        Platform.setImplicitExit(true);
    }
}

我建议您学习使用FXML和SceneBuilder。在代码中,您需要使用ColumnConstraints和RowConstraints来实现所需的功能

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Control;
import javafx.scene.control.Separator;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 *
 * @author blj0011
 */
public class JavaFXTestingGround extends Application
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        launch(args);
    }

    private StackPane root = new StackPane();
    private Scene scene = new Scene(root, 400, 400);

    @Override
    public void start(Stage primaryStage)
    {
        GridPane gridPane = new GridPane();
        gridPane.add(new Button("0 0"), 0, 0);
        gridPane.add(new Button("2 0"), 2, 0);
        gridPane.add(new Button("4 0"), 4, 0);

        gridPane.add(new Button("0 2"), 0, 2);
        gridPane.add(new Button("2 2"), 2, 2);
        gridPane.add(new Button("4 2"), 4, 2);

        gridPane.add(new Button("0 4"), 0, 4);
        gridPane.add(new Button("2 4"), 2, 4);
        gridPane.add(new Button("4 4"), 4, 4);

        Separator hSeparatorOne = new Separator(Orientation.HORIZONTAL);
        gridPane.add(hSeparatorOne, 0, 1, 5, 1);
        hSeparatorOne.setPrefHeight(10);
        hSeparatorOne.setMaxWidth(Double.MAX_VALUE);
        //hSeparatorOne.setStyle("-fx-background-color: red;");

        Separator hSeparatorTwo = new Separator(Orientation.HORIZONTAL);
        gridPane.add(hSeparatorTwo, 0, 3, 5, 1);
        hSeparatorTwo.setPrefHeight(10);
        hSeparatorTwo.setMaxWidth(Double.MAX_VALUE);
        //hSeparatorTwo.setStyle("-fx-background-color: red;");

        Separator vSeparatorOne = new Separator(Orientation.VERTICAL);
        gridPane.add(vSeparatorOne, 1, 0, 1, 5);
        vSeparatorOne.setPrefWidth(10);
        vSeparatorOne.setMaxHeight(Double.MAX_VALUE);
        //vSeparatorOne.setStyle("-fx-background-color: red;");

        Separator vSeparatorTwo = new Separator(Orientation.VERTICAL);
        gridPane.add(vSeparatorTwo, 3, 0, 1, 5);
        vSeparatorTwo.setPrefWidth(10);
        vSeparatorTwo.setMaxHeight(Double.MAX_VALUE);
        //vSeparatorTwo.setStyle("-fx-background-color: red;");

        ColumnConstraints columnConstraintsColumnZero = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsSeperatorOne = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsColumnTwo = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsSeperatorThree = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsColumnFour = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        gridPane.getColumnConstraints().addAll(columnConstraintsColumnZero, columnConstraintsSeperatorOne, columnConstraintsColumnTwo, columnConstraintsSeperatorThree, columnConstraintsColumnFour);

        RowConstraints rowConstraintsRowZero = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsSeperatorOne = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsRowTwo = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsSeperatorThree = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsRowFour = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        gridPane.getRowConstraints().addAll(rowConstraintsRowZero, rowConstraintsSeperatorOne, rowConstraintsRowTwo, rowConstraintsSeperatorThree, rowConstraintsRowFour);

        gridPane.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
        root.getChildren().add(gridPane);

        primaryStage.setTitle("Test");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

我建议您学习使用FXML和SceneBuilder。在代码中,您需要使用ColumnConstraints和RowConstraints来实现所需的功能

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Control;
import javafx.scene.control.Separator;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 *
 * @author blj0011
 */
public class JavaFXTestingGround extends Application
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        launch(args);
    }

    private StackPane root = new StackPane();
    private Scene scene = new Scene(root, 400, 400);

    @Override
    public void start(Stage primaryStage)
    {
        GridPane gridPane = new GridPane();
        gridPane.add(new Button("0 0"), 0, 0);
        gridPane.add(new Button("2 0"), 2, 0);
        gridPane.add(new Button("4 0"), 4, 0);

        gridPane.add(new Button("0 2"), 0, 2);
        gridPane.add(new Button("2 2"), 2, 2);
        gridPane.add(new Button("4 2"), 4, 2);

        gridPane.add(new Button("0 4"), 0, 4);
        gridPane.add(new Button("2 4"), 2, 4);
        gridPane.add(new Button("4 4"), 4, 4);

        Separator hSeparatorOne = new Separator(Orientation.HORIZONTAL);
        gridPane.add(hSeparatorOne, 0, 1, 5, 1);
        hSeparatorOne.setPrefHeight(10);
        hSeparatorOne.setMaxWidth(Double.MAX_VALUE);
        //hSeparatorOne.setStyle("-fx-background-color: red;");

        Separator hSeparatorTwo = new Separator(Orientation.HORIZONTAL);
        gridPane.add(hSeparatorTwo, 0, 3, 5, 1);
        hSeparatorTwo.setPrefHeight(10);
        hSeparatorTwo.setMaxWidth(Double.MAX_VALUE);
        //hSeparatorTwo.setStyle("-fx-background-color: red;");

        Separator vSeparatorOne = new Separator(Orientation.VERTICAL);
        gridPane.add(vSeparatorOne, 1, 0, 1, 5);
        vSeparatorOne.setPrefWidth(10);
        vSeparatorOne.setMaxHeight(Double.MAX_VALUE);
        //vSeparatorOne.setStyle("-fx-background-color: red;");

        Separator vSeparatorTwo = new Separator(Orientation.VERTICAL);
        gridPane.add(vSeparatorTwo, 3, 0, 1, 5);
        vSeparatorTwo.setPrefWidth(10);
        vSeparatorTwo.setMaxHeight(Double.MAX_VALUE);
        //vSeparatorTwo.setStyle("-fx-background-color: red;");

        ColumnConstraints columnConstraintsColumnZero = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsSeperatorOne = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsColumnTwo = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsSeperatorThree = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        ColumnConstraints columnConstraintsColumnFour = new ColumnConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, HPos.CENTER, true);
        gridPane.getColumnConstraints().addAll(columnConstraintsColumnZero, columnConstraintsSeperatorOne, columnConstraintsColumnTwo, columnConstraintsSeperatorThree, columnConstraintsColumnFour);

        RowConstraints rowConstraintsRowZero = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsSeperatorOne = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsRowTwo = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsSeperatorThree = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        RowConstraints rowConstraintsRowFour = new RowConstraints(Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE, Control.USE_PREF_SIZE, Priority.SOMETIMES, VPos.CENTER, true);
        gridPane.getRowConstraints().addAll(rowConstraintsRowZero, rowConstraintsSeperatorOne, rowConstraintsRowTwo, rowConstraintsSeperatorThree, rowConstraintsRowFour);

        gridPane.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
        root.getChildren().add(gridPane);

        primaryStage.setTitle("Test");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

请注意,这只是为了调试。@swpalmer我试图实现您的解决方案,但在如何在代码中实现它方面遇到了问题。我尝试过这个方法,但没有效果。请注意,这只是为了调试。@swpalmer我尝试过实现您的解决方案,但在如何在代码中实现它方面遇到了问题。我试过了,但是没有用。你需要发布你的代码,并展示你所拥有的和你想要实现的东西的图像。如果我不得不猜测的话,你可能只需要在节点之间的GrindPane单元格中有这条线。你需要发布你的代码,并显示你所拥有的以及你试图实现的东西的图像。如果让我猜的话,你可能只需要在节点之间的GrindPane单元格中画一条线,这正是我需要的。你知道如何设置这些线条的笔划长度吗?我尝试设置样式
hSeparatorOne.setStyle(“-fx笔划宽度:30;”)
并更改其pref height会更改行之间的间距。我该怎么做?谢谢。我尝试过这个解决方案,但它只改变了行和列的一部分的颜色。这里是它看起来像我只是想它采取之间的线和颜色的一部分的所有区域。我在度假。我稍后再看。你好@user3845934。如果这个答案解决了你原来的问题,接受它并提出一个新问题。这正是我所需要的。你知道如何设置这些线条的笔划长度吗?我尝试设置样式
hSeparatorOne.setStyle(“-fx笔划宽度:30;”)
并更改其pref height会更改行之间的间距。我该怎么做?谢谢。我尝试过这个解决方案,但它只改变了行和列的一部分的颜色。这里是它看起来像我只是想它采取之间的线和颜色的一部分的所有区域。我在度假。我稍后再看。你好@user3845934。如果这个答案解决了你原来的问题,接受它并提出一个新问题。