I am working on a grammar analysis program. I am using a GridPane and have three TextAreas so far. The TextArea paliVerse should span over two rows; the TextArea analysis over four. However, when I change the TextArea analysis with
gridPane.add(analysis,2,1,4,1);
analysis.setPrefRowCount(4);
the TextArea paliVerse also spans over rows, even though the PrefRowCount is 2:
How can I change this so that it looks like:
This is the relevant code:
package com.example.projektver180523;
import java.sql.*;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class HelloApplication extends Application {
private ComboBox<Integer> comboBox;
private TextArea paliVerse;
private TextArea paliVerseGER;
private TextArea analysis;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws SQLException {
// Erstelle die ComboBox
comboBox = new ComboBox<>();
// Fülle die ComboBox automatisch
fillComboBox();
// Erstelle die TextAreas
paliVerse = new TextArea();
paliVerseGER = new TextArea();
analysis = new TextArea();
// Textfeld ist unveränderlich
paliVerse.setEditable(false);
paliVerseGER.setEditable(false);
analysis.setEditable(false);
// 2 columns preferred
paliVerse.setPrefColumnCount(2);
paliVerseGER.setPrefColumnCount(2);
// // 2 rows preferred for paliVerse and German translation textArea
paliVerse.setPrefRowCount(2);
paliVerseGER.setPrefRowCount(2);
analysis.setPrefRowCount(4);
GridPane.setConstraints(comboBox, 0, 1);
GridPane gridPane = new GridPane();
// Abstand nach innen setzen
gridPane.setPadding(new Insets(10));
// horizontaler Abstand zwischen Kindern
gridPane.setHgap(10);
// vertikaler Abstand zwischen Kindern
gridPane.setVgap(10);
// Spalte 0 ist 150 weit
gridPane.getColumnConstraints().add(new ColumnConstraints(230));
// Spalte 0 ist 480 weit
gridPane.getColumnConstraints().add(new ColumnConstraints(600));
gridPane.add(new Label("Vers Nummer:"), 0, 0);
gridPane.add(comboBox, 1, 0);
gridPane.add(new Label("Palitext:"), 0, 1);
gridPane.add(paliVerse, 1, 1);
gridPane.add(new Label("Übersetzung Deutsch:"), 0, 2);
gridPane.add(paliVerseGER, 1, 2);
gridPane.add(new Label("Analyse:"), 2, 0);
gridPane.add(analysis, 2, 1, 4, 1);
Scene scene = new Scene(gridPane, 1200, 400);
// Verknüpfe CSS-Datei
scene.getStylesheets().add("styles.css");
// Zeige das Hauptfenster an
stage.setTitle("Dhammapada Reader");
stage.setScene(scene);
stage.show();
}
}


You seem to be making this more complicated than it needs to be. Each cell in
GridPanewill be sized to accomodate theNodeit contains, as stated in the class documentation:So all you need do is explicitly set the row span for [
TextArea]analysisto 2 (two).Consider the following code:
(Note that the actual contents of the
ComboBoxis irrelevant to your question so the below code does not populate theComboBox. Besides, your question doesn't contain the code for methodfillComboBoxanyway.)This is how it looks: