-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
7u6
-
2.1 GA, 2.2 beta b15
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();
}
}
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();
}
}
- duplicates
-
JDK-8115642 Label in GridPane with wrap=true in column span of 2 is broken
-
- Closed
-