JavaFX: scrollbar does not match parent

I would like to create the following scene:

+-----------------------------------------------+ |ROOT (=BorderPane) | | | | +-------------------------------------------+ | | |TOOL BAR | | | |(north) | | | +-------------------------------------------+ | | | | +-------------------------------------------+ | | |MyConfigurationComponent extends BorderPane| | | |(center) | | | | +-------------------------+ +---------+ | | | | |ScrollPane | | | | | | | |(center) | | | | | | | | +---------------------+ | | | | | | | | | | | | | | | | | | | | | | SIDE | | | | | | | CANVAS | | | PANE | | | | | | | | | | (right) | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------+ | | | | | | | | | | | | | | | +-------------------------+ +---------+ | | | | | | | +-------------------------------------------+ | | | +-----------------------------------------------+ 

Expectation

I would like to make ScrollPane as large as possible. This means that the ScrollPane must grow and fill the entire area, regardless of the size of the scene.

Since both TOOL BAR and SIDE PANE have a fixed (preferred) width and height, I thought ScrollPane stretch and fill the rest of the area.

Actual behavior

But this is not so. ScrollPane somehow magically sets its minimum size to about 40x40. The height is stretched according to the height of the SIDE PANEL , but the width remains the same and nothing can change it.

In fact, the only thing that makes ScrollPane bigger was to explicitly set minWidth to some value (i.e. 400). But this does not solve the problem of cropping ScrollPane .

When I set the background color in MyConfigurationComponent , I see that the background color fills the entire area as expected (so the problem is not in MyConfigurationComponent ). Apparently, its center child ( ScrollPane ) is displayed as left, its right child ( SIDE PANEL ) as center, because all other areas on the right side remain empty (but with the background, so it is still MyConfigurationComponent !).

What i tried

  • set min , pref and max ScrollPane sizes for specific values
  • snap preferred size to parent size
  • set fitToWidth and fitToHeight to true
  • wrap ScrollPane with AnchorPane to all four sides
  • wrap ScrollPane with VBox and set priority for everyone

Current workaround

Bind the width of MyConfigurationComponent minus the width from SIDE PANEL to ScrollPane . Wrong in different ways.

code

ROOT.fxml

 <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cz.upol.fapapp.cfa.gui.frame.FxCFAConfigFrameController"> <top> <ToolBar> <Button text="Some button" /> </ToolBar> </top> <center> <MyConfigurationComponent fx:id="configComp" /> </center> </BorderPane> 

MyConfigurationComponent.fxml

 <BorderPane xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"> <center> <ScrollPane fx:id="scrollPane"> <content> <Canvas width="2000" height="2000" /> </content> </ScrollPane> </center> <right> <VBox prefWidth="100.0" BorderPane.alignment="CENTER_RIGHT"> <children> <Label text="Colors" /> <ComboBox fx:id="cmbColors" prefWidth="100.0" /> <!-- ... --> <Separator prefHeight="15.0" prefWidth="100.0" /> <Button mnemonicParsing="false" text="Action 1" /> <Button mnemonicParsing="false" text="Action 2" /> </children> </VBox> </right> </BorderPane> 

Questions

  • BorderPane Center is expanding its size to fill the content, right?
  • Could this be caused by BorderPane inside BorderPane ?
  • Is there a better solution than โ€œmy workaroundโ€?
+5
source share

Source: https://habr.com/ru/post/1271399/


All Articles