0

I can't seem to remove the left and right border of this GridPane. See picture below.

Left and Right border

My FXML file is

<?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>

As you can see I already tried setting insets to 0, and making the border transparent but that doesn't work.

2 Answers 2

0

Your problem is simple - your columns have percentWidth set, but the total percent adds up to 99%, not 100%. Either change all of the percentages to 33.33..., or else change one of them to 34% while the other two remain 33%.

0

I know this long time over, but the better way would probably be to set percentWidth to 100 in each column.

The documentation states:

Note that if the sum of the widthPercent (or heightPercent) values total greater than 100, the values will be treated as weights. e.g. if 3 columns are each given a widthPercent of 50, then each will be allocated 1/3 of the gridpane's available width (50/(50+50+50)).

Setting to 100 will ensure in any number of columns that they will all have the same width.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.