The code below generates this screen shot:
The label below the 2nd column does not want to properly claim extra space when it needs to be wrapped. This only occurs when the columns use percentage widths -- the docs say it will ignore all other properties in that case, including hgrow etc, but it does not mention it would also affect how rows work.. but it looks like it does.
Anyone got a work-around or can tell me what I'm doing wrong? All I want is to display 3 images, with labels of unknown size below them that are nicely spaced and aligned and all the same size... Something like this:
The above is done with a custom control, tentatively named "BetterGridPane"...
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;
import javafx.stage.Stage;
public class TestLabelWrap extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
GridPane root = new GridPane();
root.add(new ListView(FXCollections.observableArrayList("1", "2", "3")), 0, 0);
root.add(new ListView(FXCollections.observableArrayList("1", "2", "3")), 1, 0);
root.add(new ListView(FXCollections.observableArrayList("1", "2", "3")), 2, 0);
root.add(new Label("Value A"), 0, 1);
root.add(new Label("The value for this porperty is so large it wraps, The value for this porperty is so large it wraps") {{
setWrapText(true);
}}, 1, 1);
root.add(new Label("Value C"), 2, 1);
root.getColumnConstraints().add(new ColumnConstraints() {{ setPercentWidth(33.33); }});
root.getColumnConstraints().add(new ColumnConstraints() {{ setPercentWidth(33.33); }});
root.getColumnConstraints().add(new ColumnConstraints() {{ setPercentWidth(33.33); }});
root.getRowConstraints().add(new RowConstraints() {{ setVgrow(Priority.NEVER); }});
root.getRowConstraints().add(new RowConstraints() {{ setVgrow(Priority.ALWAYS); }});
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}