I´m just facing a little issue that I can´t solve by myself. I try to place a vBox including a TextField and a HTML-Editor in my BorderPane, but the full space is not used. Another problem is that if I shrink the window, the html-editor overlaps with my left option window.
private void initEditor()
{
editor = new HTMLEditor();
editor.setId("editor");
editor.lookup(".top-toolbar").setDisable(true);
editor.lookup(".top-toolbar").setManaged(false);
((ToolBar) editor.lookup(".bottom-toolbar")).getItems().addAll(FXCollections.observableArrayList(((ToolBar)editor.lookup(".top-toolbar")).getItems()));
editorBox = new VBox();
TextField field = new TextField();
field.setPrefHeight(36);
field.setId("editor-title");
editorBox.setFillWidth(true);
editorBox.getChildren().addAll(field, editor);
root.setCenter(editorBox);
}
How to set and resize ScrollPane with FXML:
!!! NewMessage.fxml need start with VBox panel !!!
Comment or delete this 2 lines if u don't need load FXML:
And layout:
Layout image (topBar, leftBar, scrollContentPane)
OK, so a few things going wrong here, I'll try to address them provide some advice and a sample solution.
You need to use the VBox.setVgrow(editor, Priority.ALWAYS) method to get the HTMLEditor to take up any extra space in the VBox. Also, make sure that the HTMLeditor has an unbounded max height so that it can grow to fit the available area, for example
editor.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE)
. CallingeditorBox.setFillWidth(true)
is redundant as the default value for thefillWidth
property istrue
.But even if you do all that, (as of 2.2b13) there is a bug in WebPane sizing which will cause you problems. Internally the WebPane is implemented as a GridPane containing the Toolbar and an editable WebView. By default, WebView has a preferred size of 800x600. The HtmlEditor control does not set the GridPane constraints for the WebView to allow it to be sized past it's preferred size.
To work around this, you can lookup the WebView via a css lookup after it has been added to an active Scene and adjust the GridPane constraints manually. Here is some code to do that:
Explicitly set the minimum width setting for the center pane in your BorderPane so that it won't overflow over the outer edge Panes.
You need to do this because the BorderPane documentation states:
As an aside the lookup calls in your code are suspicious. Normally you can't lookup nodes by css ID until the node has been added to an active scene on a displayed stage and the JavaFX system has had a chance to run a CSS layout pass on the node - otherwise the lookup will just return null.
For debugging JavaFX layout issues, the ScenicView application is invaluable.
Here is a complete example to generate a layout similar to the image linked in your question, but without the issues you mention.
I was also facing the same kind of issue. My anchorPane inside borderPane was not filling up. Setting a large number for prefSize worked for me. So when border pane grows, it tries to provide as much size as possible to its child