Skip to content
Advertisement

Achieve Unique Column Width for each Cell in Different Rows with a GridPane?

I am trying to model credit card data in JavaFx using a GridPane:

My model contains 3 rows (Note: each field is comprised of label + text field):

Row 1: First name and last name (4 fields)

Row 2: Credit card number (2 fields)

Row 3: Expiration date – month, year + CVV (6 fields)

See screenshot below:

Card Data Model

I was reading this tutorial which states:

All cells in the same row will have the same height, and all cells in the same column will have the same width. Different rows can have different heights and different columns can have different widths.

Are there any workarounds to to have different size columns on a row by row basis in a GridPane?

Advertisement

Answer

For the specific layout in the image, I would use a VBox with HBox for rows:

JavaScript

Output:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement