-
Bug
-
Resolution: Fixed
-
P3
-
8
-
Windows 7 64-bit
Java 8u40-b20
The row height is computed incorrectly in Java 8. Works in Java 7.
Here is my test case:
package gridpanelayoutissues;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import static javafx.scene.layout.Region.USE_COMPUTED_SIZE;
import static javafx.scene.layout.Region.USE_PREF_SIZE;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class GridPaneLayoutIssues extends Application {
@Override
public void start(Stage primaryStage) {
GridPane gp2 = makeGridPane();
TitledPane tp2 = new TitledPane("Sub-Group", gp2);
GridPane.setColumnSpan(tp2, 2);
CheckBox showbtn = new CheckBox("(toggle me)");
showbtn.setSelected(true);
int row = 0;
gp2.addRow(row++, new Label("Show widget"), showbtn);
VBox widget = new VBox();
// THIS LINE IS THE WORKAROUND
//widget.setMinHeight(USE_PREF_SIZE);
widget.getChildren().setAll(new Button("A Button..."), new TextArea(
"A TextArea\nThat has enough content to need both horizontal and vertical scroll bars.\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nin it.\nJust because."));
Node wrappedWidget = wrap(widget);
Label label = new Label("Label");
gp2.addRow(row++, label, wrappedWidget);
label.managedProperty().bind(label.visibleProperty());
label.visibleProperty().bind(showbtn.selectedProperty());
wrappedWidget.managedProperty().bind(wrappedWidget.visibleProperty());
wrappedWidget.visibleProperty().bind(showbtn.selectedProperty());
VBox vb = new VBox();
vb.setFillWidth(true);
vb.getChildren().add(tp2);
Scene scene = new Scene(vb, 300, 350);
primaryStage.setTitle("Strange Layout. Regression from Java 7");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
private GridPane makeGridPane() {
GridPane gp = new GridPane();
gp.setPadding(new Insets(10));
gp.setVgap(6);
ColumnConstraints labelColumnContraints = new ColumnConstraints(20, USE_COMPUTED_SIZE, USE_PREF_SIZE, Priority.NEVER, HPos.LEFT, true);
ColumnConstraints valueColumnContraints = new ColumnConstraints(50, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.LEFT, true);
gp.getColumnConstraints().setAll(labelColumnContraints, valueColumnContraints);
return gp;
}
private Node wrap(Node widget) {
Button contextButton = new Button("X");
HBox glue = new HBox(0); // if the wrapped widget can't grow, this will take up space instead
glue.setMaxWidth(Double.MAX_VALUE);
HBox hbox = new HBox(2);
hbox.setMaxWidth(Double.MAX_VALUE);
hbox.setMaxHeight(Double.MAX_VALUE);
hbox.setAlignment(Pos.BASELINE_LEFT);
hbox.getChildren().addAll(widget, glue, contextButton);
HBox.setHgrow(widget, Priority.ALWAYS);
HBox.setHgrow(glue, Priority.SOMETIMES);
HBox.setHgrow(contextButton, Priority.NEVER);
VBox vbox = new VBox();
vbox.getChildren().add(hbox);
VBox.setVgrow(hbox, Priority.ALWAYS);
// real app has conditional add of a label to the vbox (VBox is there for a reason)
return vbox;
}
}
Here is my test case:
package gridpanelayoutissues;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import static javafx.scene.layout.Region.USE_COMPUTED_SIZE;
import static javafx.scene.layout.Region.USE_PREF_SIZE;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class GridPaneLayoutIssues extends Application {
@Override
public void start(Stage primaryStage) {
GridPane gp2 = makeGridPane();
TitledPane tp2 = new TitledPane("Sub-Group", gp2);
GridPane.setColumnSpan(tp2, 2);
CheckBox showbtn = new CheckBox("(toggle me)");
showbtn.setSelected(true);
int row = 0;
gp2.addRow(row++, new Label("Show widget"), showbtn);
VBox widget = new VBox();
// THIS LINE IS THE WORKAROUND
//widget.setMinHeight(USE_PREF_SIZE);
widget.getChildren().setAll(new Button("A Button..."), new TextArea(
"A TextArea\nThat has enough content to need both horizontal and vertical scroll bars.\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nlines\nin it.\nJust because."));
Node wrappedWidget = wrap(widget);
Label label = new Label("Label");
gp2.addRow(row++, label, wrappedWidget);
label.managedProperty().bind(label.visibleProperty());
label.visibleProperty().bind(showbtn.selectedProperty());
wrappedWidget.managedProperty().bind(wrappedWidget.visibleProperty());
wrappedWidget.visibleProperty().bind(showbtn.selectedProperty());
VBox vb = new VBox();
vb.setFillWidth(true);
vb.getChildren().add(tp2);
Scene scene = new Scene(vb, 300, 350);
primaryStage.setTitle("Strange Layout. Regression from Java 7");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
private GridPane makeGridPane() {
GridPane gp = new GridPane();
gp.setPadding(new Insets(10));
gp.setVgap(6);
ColumnConstraints labelColumnContraints = new ColumnConstraints(20, USE_COMPUTED_SIZE, USE_PREF_SIZE, Priority.NEVER, HPos.LEFT, true);
ColumnConstraints valueColumnContraints = new ColumnConstraints(50, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.LEFT, true);
gp.getColumnConstraints().setAll(labelColumnContraints, valueColumnContraints);
return gp;
}
private Node wrap(Node widget) {
Button contextButton = new Button("X");
HBox glue = new HBox(0); // if the wrapped widget can't grow, this will take up space instead
glue.setMaxWidth(Double.MAX_VALUE);
HBox hbox = new HBox(2);
hbox.setMaxWidth(Double.MAX_VALUE);
hbox.setMaxHeight(Double.MAX_VALUE);
hbox.setAlignment(Pos.BASELINE_LEFT);
hbox.getChildren().addAll(widget, glue, contextButton);
HBox.setHgrow(widget, Priority.ALWAYS);
HBox.setHgrow(glue, Priority.SOMETIMES);
HBox.setHgrow(contextButton, Priority.NEVER);
VBox vbox = new VBox();
vbox.getChildren().add(hbox);
VBox.setVgrow(hbox, Priority.ALWAYS);
// real app has conditional add of a label to the vbox (VBox is there for a reason)
return vbox;
}
}