简体   繁体   中英

JavaFX: why scrollpane is including a splitpane?

I am trying to understand how widgets in JavaFX work, and given the following FXML I don't get why a ScrollPane is putting a split in after the ListView :

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.Group?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0"
            prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <top>
        <Pane prefHeight="195.0" prefWidth="600.0" BorderPane.alignment="CENTER">
            <children>
                <Group>
                    <children>
                        <Label layoutX="58.0" layoutY="25.0" prefHeight="15.0" prefWidth="80.0" text="Testlabel "/>
                    </children>
                </Group>
            </children>
        </Pane>
    </top>
    <center>
        <ScrollPane fx:id="scrollPane" prefHeight="200.0" prefWidth="600.0" BorderPane.alignment="CENTER">
            <content>
                <ListView/>
            </content>
        </ScrollPane>
    </center>
    <bottom>
        <ToolBar layoutX="-86.0" layoutY="150.0" prefWidth="200.0">
            <items>

            </items>
        </ToolBar>
    </bottom>
</BorderPane>

I just want to have a ListView with a possiblity to scroll if the list is too long. Using JavaFX included in the latest JDK 8 (1.8.0_05) on Linux Mint.

Putting minWidth="600" as an attribute of ListView fixes the problem:

    <ScrollPane fx:id="scrollPane" prefHeight="100.0" prefWidth="600.0" BorderPane.alignment="CENTER">
        <ListView minWidth="600"/>
    </ScrollPane>

But I must admit it is utterly unintuitive. JavaFX should figure by itself out what the preferred width should be. Smells like Swing people developing JavaFX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM