텍스트 제목과 4 개의 버튼이있는 fxml의 GridPane이 있습니다. GridPane 자체는 중앙에 정렬되지만 모든 버튼은 격자의 열 안에 정렬됩니다. Java 코드를 사용하여 항목의 정렬을 변경하는 방법을 알고 있지만 이상적인 상황은 아닙니다. FXML 및 CSS를 사용하여 모든 스타일을 처리하고 싶습니다. 누구든지 JavaFX의 GridPane 뷰에서 셀의 요소 정렬을 중앙 정렬하는 가장 좋은 방법을 제안 할 수 있습니까? FXML에서센터 정렬 JavaFX의 GridPane 행
5
A
답변
3
:
<GridPane ...>
<columnConstraints>
<!-- one of these for each column: you can obviously have other properties set here if needed -->
<ColumnConstraints halignment="CENTER" />
</columnConstraints>
</GridPane>
0
당신은 개별적으로 GridPane에서 각 개체를 정렬 할 필요가 아닌 GridPane 자체.
이렇게하려면 Layout : ObjectName (예 : Button)으로 이동하고 HAlignment에서 CENTER를 선택하십시오.
11
GridPane
의 자식을 가운데로 정렬하도록 설정하려면 자식 노드의 Halignment 및 Valignment을 설정해야합니다. 당신이 원하는 경우이를 달성 할 수있는 쉬운 방법이 있습니다
<GridPane>
... // other properties
<children>
<Button mnemonicParsing="false" text="Button" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
</children>
</GridPane>
:
GridPane.setHalignment(node, HPos.CENTER); // To align horizontally in the cell
GridPane.setValignment(node, VPos.CENTER); // To align vertically in the cell
FMXL에서 당신에 의해 유사한 효과를 얻을 수 있습니다 : 당신이 비슷한을 할 수있는 자바 코드에서
정렬 할 특정 열이나 행의 모든 노드를 같은 순서로 정렬합니다. 노드에 halignment/valignment
을 추가하는 대신 ColumnConstraints 또는 RowConstraints을 만들어 GridPane에 추가 할 수 있습니다.
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" halignment="CENTER" minWidth="10.0" prefWidth="100.0" />
... // More constraints for other columns
</columnConstraints>
<children>
<Button mnemonicParsing="false" text="Button" />
</children>
</GridPane>
마찬가지로 RowConstraints
도 추가 할 수 있습니다.