[JavaFX] [Java8] How to use GridPane

There is not much Japanese documentation on JavaFX, so I will summarize it.

FXML editing may or may not use SceneBuilder.

Official documentation

GridPane (JavaFX 8)

Verification environment

Type version
OS Windows10 64bit
IntelliJ IDEA 2017.1.5
JDK 1.8.0_121

Basic

Create row / column

The following is an example of creating a 2x2 Grid.

2x2 Grid Pane example


<GridPane gridLinesVisible="true" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/8.0.112"
          xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
    <columnConstraints>
        <ColumnConstraints/>
        <ColumnConstraints/>
    </columnConstraints>
    <rowConstraints>
        <RowConstraints/>
        <RowConstraints/>
    </rowConstraints>
</GridPane>

You can extend the grid by adding child elements inside columnConstraints, rowConstraints. It seems that this is not much different from the WPF Grid specifications.

Control assignment

Control assignment


<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1"
          xmlns="http://javafx.com/javafx/8.0.112" fx:controller="sample.Controller">
    <rowConstraints>
        <RowConstraints/>
        <RowConstraints/>
    </rowConstraints>
    <columnConstraints>
        <ColumnConstraints/>
        <ColumnConstraints/>
    </columnConstraints>
    <children>
        <Label text="Label" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
    </children>
</GridPane>

Width to parent element

python


<GridPane hgap="10" vgap="10" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
    <rowConstraints>
        <RowConstraints percentHeight="100" />
    </rowConstraints>
    <columnConstraints>
        <ColumnConstraints percentWidth="50" />
        <ColumnConstraints percentWidth="50"/>
    </columnConstraints>
   <children>
      <TextArea prefHeight="200.0" prefWidth="200.0" />
      <TextArea prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" />
   </children>
</GridPane>

You can set a percentage for each element.

8bf6abbf-13bb-486d-8230-8ad3101cdbaf.gif

todo: What happens when the size specification and the percentage specification are combined?

reference

java - JavaFX - Get GridPane to fit parent - Stack Overflow

Editing with SceneBuilder

Add row / column

It seems easy to add from the right-click menu on the left menu.

grid.gif

reference

GridPane (JavaFX 8)

Recommended Posts

[JavaFX] [Java8] How to use GridPane
[Java] How to use Map
[Java] How to use Map
How to use java Optional
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to use string.format
How to use Java Map
How to use Java variables
[Java] How to use Optional ①
How to use Java HttpClient (Get)
How to use Java HttpClient (Post)
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to use Java lambda expressions
[Java] How to use Math class
How to use Java enum type
[Java] How to use the File class
[Java] How to use the hasNext function
How to use submit method (Java Silver)
[Java] How to use the HashMap class
[Easy-to-understand explanation! ] How to use Java instance
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
[Java] [Maven3] Summary of how to use Maven3
[Processing × Java] How to use the class
How to use Java Scanner class (Note)
[Processing × Java] How to use the function
[Easy-to-understand explanation! ] How to use ArrayList [Java]
[Java] How to use the Calendar class
[Java] Learn how to use Optional correctly
[Easy-to-understand explanation! ] How to use Java overload
try-catch-finally exception handling How to use java
[Easy-to-understand explanation! ] How to use Java encapsulation
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM