This discussion is archived
1 Reply Latest reply: Jan 2, 2013 10:51 AM by 945099 RSS

Strange GridPane behaviour in relation to column width

945099 Newbie
Currently Being Moderated
I want to create GridPane. It must look as
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃label00 (long long long text)           ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┫
┃label01                         ┃label11┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛
and I write code for it:
public void start(Stage stage) throws Exception
{
    BorderPane rootPane = new BorderPane();
    Scene scene = new Scene(rootPane, 400, 200);
    stage.setScene(scene);
    
    GridPane gridPane = new GridPane();
    rootPane.setCenter(gridPane);
    gridPane.setGridLinesVisible(true);
    
    //first row
    Label l00 = new Label("label00 (long long long text)");
    gridPane.add(l00, 0, 0, 2, 1);
    //second row
    Label l01 = new Label("label11");
    Label l11 = new Label("label11");
    gridPane.add(l01, 0, 1, 1, 1);
    gridPane.add(l11, 1, 1, 1, 1);
    GridPane.setHgrow(l01, Priority.ALWAYS);
    
    stage.show();
}
But as result I see
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃label00 (long long long text)           ┃
┣━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┫
┃label01               ┃label11          ┃
┗━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━┛
The cell with Label11 is wider then need. Label01 has GridPane.hgrow="always", but Label11 is not pinned to the right edge.

I change l00.text, and do them no so long.
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃label00 (long text)                     ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┫
┃label01                     ┃label11    ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━┛
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃label00                                 ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┫
┃label01                         ┃label11┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛
Why does width of Label11 column depend on the content of first row cell, that spans two columns?
How to solve this problem?

Edited by: Valery Qwertovsky on 30.12.2012 8:49

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points