我似乎无法删除此 GridPane 的左右边框。见下图。
我的 FXML 文件是
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-box-border: transparent;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<padding>
<javafx.geometry.Insets top="0" right="0" left="0" bottom="0"/>
</padding>
<columnConstraints>
<ColumnConstraints percentWidth="33.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="33.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="33.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="33.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" percentHeight="33.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: red;" />
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: red;" GridPane.columnIndex="2" GridPane.rowIndex="1" />
</children>
</GridPane>
如您所见,我已经尝试将 insets 设置为 0,并使边框透明,但这不起作用。
最佳答案
您的问题很简单 - 您的列设置了 percentWidth
,但总百分比加起来为 99%,而不是 100%。要么将所有百分比更改为 33.33...,要么将其中一个更改为 34%,而其他两个保持 33%。
关于css - JavaFX 从 Pane 中删除填充/边距/边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34623208/