Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Span selected Nodes after have declared the number of comumns and rows in javafx

I would to know the way to span the next node in the second column after the node containing the labal "Info" to the rest of the remaining columns and on 3 rows below.

Below is my present output with the associated code.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class Test extends Application {

    @Override
    public void start(Stage primaryStage) {
        GridPane root = new GridPane();
        root.setGridLinesVisible(true);
        final int numCols = 5 ;
        final int numRows = 12 ;
        for (int i = 0; i < numCols; i++) {
            ColumnConstraints colConst = new ColumnConstraints();
            colConst.setPercentWidth(100.0 / numCols);
            root.getColumnConstraints().add(colConst);
        }
        for (int i = 0; i < numRows; i++) {
            RowConstraints rowConst = new RowConstraints();
            rowConst.setPercentHeight(100.0 / numRows);
            root.getRowConstraints().add(rowConst);         
        }
        
        Label nameLbl = new Label("Name");
        Label nameFld = new Label();
        Label infoLbl = new Label("Info : ");
        Label infoFld = new Label();
        infoFld.setStyle("-fx-background-color: lavender;-fx-font-size: 7pt;-fx-padding: 10 0 0 0;");   

        Button okBtn = new Button("OK");
        Button cancelBtn = new Button("Cancel");
        
        Label commentBar = new Label("Status: Ready");
        commentBar.setStyle("-fx-background-color: lavender;-fx-font-size: 7pt;-fx-padding: 10 0 0 0;");       
        
        root.add(nameLbl, 0, 0, 1, 1);   
        root.add(nameFld, 1, 0, 1, 1);   
        root.add(infoLbl, 0, 1, 1, 1);  
        root.add(infoFld, 1, 1, 4, 1);  
        root.add(okBtn, 3, 9, 1, 1);    
        root.add(cancelBtn, 2, 9, 1, 1); 
        root.add(commentBar, 0, 11, GridPane.REMAINING, 1);     
        
        primaryStage.setScene(new Scene(root, 900, 500));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

>Solution :

If you want the label to span four rows, as well as four columns, set its column span as well as its row span to 4:

    // root.add(infoFld, 1, 1, 4, 1);
    root.add(infoFld, 1, 1, 4, 4);

By default a label will not grow beyond its preferred size (which in this case is zero, because it has no text). Allow it to grow indefinitely:

infoFld.setMaxWidth(Double.MAX_VALUE);
infoFld.setMaxHeight(Double.MAX_VALUE);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading