How to bind Pane with another Pane in JavaFX

后端 未结 1 608
野的像风
野的像风 2021-01-25 15:04

I\'m finding the way that how to bind the size of a pane with the outer pane.

I could bind the size ofRectangle with Pane, But couldn\'t bind an inner pane (Red dotted

相关标签:
1条回答
  • 2021-01-25 15:54

    You do not need a binding to achieve this. The problem is the fact that you set the constraints for maxHeight/maxWidth to USE_PREF_SIZE, i.e. to a fixed value that can very well be reached when resizing the window. Remove those constraints to allow the AnchorPane to grow as necessary:

    Tab.fxml

    <AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
        ...
    </AnchorPane>
    

    Furthermore I recommend avoiding the use of AnchorPanes, if you can avoid it. It's hard to achieve responsive layouts with this kind of layout. VBox and HBox would do much better jobs in this case.

    Example:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.control.CheckBox?>
    <?import javafx.scene.control.ComboBox?>
    <?import javafx.scene.control.RadioButton?>
    <?import javafx.scene.control.TextArea?>
    <?import javafx.scene.control.ToggleGroup?>
    <?import javafx.scene.layout.HBox?>
    <?import javafx.scene.layout.VBox?>
    <?import javafx.geometry.Insets?>
    <?import javafx.scene.layout.Region?>
    
    <VBox prefHeight="480.0"
        prefWidth="1000.0" xmlns="http://javafx.com/javafx/10.0.1"
        xmlns:fx="http://javafx.com/fxml/1">
        <padding>
            <Insets topRightBottomLeft="4" />
        </padding>
        <children>
            <HBox fx:id="LabelBox" prefHeight="64.0" prefWidth="978.0" />
            <TextArea VBox.vgrow="ALWAYS" fx:id="FilePaths"
                prefHeight="128.0">
            </TextArea>
            <HBox spacing="10" minWidth="-Infinity">
                <VBox.margin>
                    <Insets top="5" left="0" right="0" bottom="0" />
                </VBox.margin>
                <children>
                    <RadioButton mnemonicParsing="false" selected="true"
                        text="Hash/Size only">
                        <toggleGroup>
                            <ToggleGroup fx:id="AnalyzeMethod" />
                        </toggleGroup>
                    </RadioButton>
                    <RadioButton mnemonicParsing="false" text="FileName"
                        toggleGroup="$AnalyzeMethod" />
                    <RadioButton mnemonicParsing="false"
                        text="Directory Structure" toggleGroup="$AnalyzeMethod" />
                    <CheckBox fx:id="CheckDiff" mnemonicParsing="false"
                        text="Show Diff" />
                    <CheckBox fx:id="CheckSame" mnemonicParsing="false"
                        text="Show Same" />
                    <Region HBox.hgrow="ALWAYS" /> <!-- placeholder to grow/shrink -->
                    <ComboBox fx:id="ComboBox" prefWidth="150.0" />
                </children>
            </HBox>
        </children>
    </VBox>
    
    0 讨论(0)
提交回复
热议问题