Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8119358

Unexpected behavior with Label#setWrapText(true) in GridPane with rowSpan=2

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 7u6
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Environment:

      2.1 GA, 2.2 beta b15

      Description

      I've noticed a strange behavior, when adding a Label with setWrapText(true) to a GridPane and add rowspan=2

      Start the sample, see the normal GridPane, then click the button, which adds some text to the Label.
      The GridPane and the lblStatus increases significantly in height and width.

      Then resize the window. The GridPane always takes the full height/width, as if some GridPane.setH/VGrow was set for the lblStatus.

      If you put the lblStatus in a cell without rowspan, than it works in normal way.


      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.layout.GridPane;
      import javafx.stage.Stage;

      public class TestApp4 extends Application {
          public static void main(String[] args) {
              launch(args);
          }


          @Override
          public void start(final Stage stage) throws Exception {

              GridPane gridPane = new GridPane();
              gridPane.setPadding(new Insets(2, 2, 2, 2));

              // Column Constraints help, but the lblStatus still occupies to much vertical space
              //gridPane.getColumnConstraints().add(new ColumnConstraints(50));
              //gridPane.getColumnConstraints().add(new ColumnConstraints(50));

              Label lblText1 = new Label();
              lblText1.textProperty().set("Some text");

              Label lblText2 = new Label();
              lblText2.textProperty().set("Some other text");

              Button btnClick = new Button();
              btnClick.textProperty().set("Click me");

              final Label lblStatus = new Label();
              lblStatus.setWrapText(true);

              gridPane.add(lblText1, 0, 0, 1, 1);
              gridPane.add(lblText2, 1, 0, 1, 1);
              gridPane.add(lblStatus, 0, 1, 2, 1); // Change the 2 to 1, to have normal behavior.
              gridPane.add(btnClick, 0, 2, 2, 1);

              btnClick.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      lblStatus.setText("very long text, very long text, very long text, very long text,very long text, very long text");
                  }
              });

              gridPane.setGridLinesVisible(true);

              Scene scene = new Scene(gridPane, 300, 300);
              stage.setScene(scene);
              stage.show();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ekrejcir Eva Krejčířová (Inactive)
              Reporter:
              cschudtjfx Christian Schudt (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: