【问题标题】:How to not show grid lines in merged cells如何在合并的单元格中不显示网格线
【发布时间】:2018-09-23 04:27:09
【问题描述】:

我的 JavaFX 窗口中有 GridPane,我跨越两列。

当我点击场景构建器中可见的网格线时,合并单元格的中间有一条线。

如何删除或不显示此行?

【问题讨论】:

  • 不要在生产代码中使用gridLinesVisible;这是给debug purposes only的。
  • 当我想看线条时应该使用什么?
  • 但是..它只是为了调试,你为什么要打扰?投入在这种边缘性上的时间完全是浪费,IMO

标签: javafx


【解决方案1】:

这是一种方法:在这种方法中,我将GridPane's 背景设为黑色。然后我拉伸每个Node 以填充它们的Cell 并使Node's 背景为白色。同样在GridPane 上,我将所有Insets 设置为5,将VGapHGap 设置为5。我建议您使用CSS 并采用@James_D 的方法here

FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<GridPane hgap="5.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: black;" vgap="5.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.60">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
   <children>
      <Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: white;" text="Label" GridPane.columnSpan="2147483647" />
      <Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: white;" text="Label" GridPane.rowIndex="1" />
      <Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: white;" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
      <Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: white;" text="Label" GridPane.rowIndex="2" />
      <Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: white;" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
   </children>
   <padding>
      <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
   </padding>
</GridPane>

但我建议你使用CSS 并遵循@James_D 的方法here

【讨论】:

    猜你喜欢
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    相关资源
    最近更新 更多