2017-04-03 4 views
0

내 자식 AnchorPanes의 크기를 조정하는 방법이 내 메인 UI Main UI중 VBOX 자바 FX

나는 중 VBOX이는 다음과 AnchorPane 내 (Fxid datePane을). Vbox는 파란색입니다.

레이블 "추가"가있는 버튼을 클릭하면 "second.fxml"파일이 VBox (Fxid : datePane)에로드됩니다.

로드 된 fxml 파일은 Vbox의 높이와 너비를 사용합니다.

second.fxml에는 빨간색의 VBox가 있습니다.

그러나 화면 크기를 조정하면로드 된 파일의 높이와 너비가 그에 따라 변경되지 않습니다. After resizing the screen

로드 된 fxml 파일이 상위 VBox (Fxid : datePane)의 너비와 높이를 가져 오도록하려면 어떻게해야합니까 ???

이이 내 Main.java 파일

@FXML 
private VBox vbxsecond; 

@FXML 
    private VBox datePane; 

@Override 
public void start(Stage primaryStage) { 
    try { 
     //BorderPane root = new BorderPane(); 
     Parent root = FXMLLoader.load(getClass().getResource("/resources/dashboard.fxml")); 
     Scene scene = new Scene(root); 
     scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); 
     primaryStage.setScene(scene); 
     //primaryStage.setMaximized(true); 
     primaryStage.show();    
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
} 

public static void main(String[] args) { 
    launch(args); 
} 

내 FxmlController.java 파일

@FXML 
private Button btnAdd; 

@FXML 
private VBox datePane; 

@FXML 
    private VBox vbxsecond; 

@FXML 
private VBox vbxThird; 

@FXML 
private AnchorPane apLoader; 

VBox v; 

@Override 
public void initialize(URL arg0, ResourceBundle arg1) { 
    // TODO Auto-generated method stub 
    double w = apLoader.getWidth(); 
    double h = apLoader.getHeight(); 
    System.out.println(h); 
} 

public void setDataPane(Node node) { 
    // update VBox with new form(FXML) depends on which button is clicked 
    datePane.getChildren().setAll(node); 

} 

public VBox fadeAnimate(String url) throws IOException { 
    v = (VBox) FXMLLoader.load(getClass().getResource(url)); 
    FadeTransition ft = new FadeTransition(Duration.millis(1500)); 
    ft.setNode(v); 
    ft.setFromValue(0.1); 
    ft.setToValue(1); 
    ft.setCycleCount(1); 
    ft.setAutoReverse(false); 
    double w = datePane.getWidth(); 
    double h = datePane.getHeight(); 
    v.setPrefHeight(h); 
    v.setPrefWidth(w); 

    ft.play(); 
    return v; 


} 

public void loadPane() throws IOException { 

    try{ 

     setDataPane(fadeAnimate("/resources/second.fxml")); 


    }catch(IOException e) 
    { 
     e.printStackTrace(); 
    } 

} 

public void loadPane2() throws IOException { 

    try{ 

     setDataPane(fadeAnimate("/resources/third.fxml")); 


    }catch(IOException e) 
    { 
     e.printStackTrace(); 
    } 

} 

않습니다이 내 두 번째 내 dashboard.fxml 파일

AnchorPane minHeight="800.0" prefHeight="800.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.FxmlController"> 
    <children> 
     <SplitPane dividerPositions="0.29797979797979796" layoutX="14.0" layoutY="14.0" prefHeight="800.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> 
     <items> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="798.0" prefWidth="192.0"> 
       <children> 
        <Button fx:id="btnAdd" layoutX="22.0" layoutY="122.0" mnemonicParsing="false" onAction="#loadPane" prefHeight="25.0" prefWidth="51.0" text="Add" AnchorPane.leftAnchor="22.0" AnchorPane.topAnchor="122.0" /> 
        <Button fx:id="btnadd2" layoutX="57.0" layoutY="281.0" mnemonicParsing="false" onAction="#loadPane2" text="ADD second" /> 
       </children> 
      </AnchorPane> 
      <AnchorPane fx:id="apLoader" minHeight="0.0" minWidth="0.0" prefHeight="158.0" prefWidth="814.0"> 
       <children> 
        <VBox fx:id="datePane" layoutX="10.0" layoutY="23.0" prefHeight="798.0" prefWidth="628.0" style="-fx-background-color: Blue;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> 
       </children> 
      </AnchorPane> 
     </items> 
     </SplitPane> 
    </children> 
</AnchorPane> 

입니다 .fxml 파일

<VBox fx:id="vbxsecond" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="814.0" style="-fx-background-color: Red;" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <Label fx:id="vbxSecond" text="HELLOOO" VBox.vgrow="ALWAYS"> 
     <font> 
      <Font size="96.0" /> 
     </font> 
     </Label> 
    </children> 
</VBox> 

이 내 third.fxml 파일

나는이 문제를 해결
<VBox fx:id="vbxThird" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="814.0" style="-fx-background-color: Pink;" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <Label text="Third HELOO" VBox.vgrow="ALWAYS"> 
     <font> 
      <Font size="85.0" /> 
     </font> 
     </Label> 
    </children> 
</VBox> 
+0

모든 제약 조건을 0으로 설정합니다. – Sedrick

답변

0

입니다. 난 그냥 second.fxml의 중 VBOX의 값을 설정했고, 중 VBOX (Fxid : datePane)을 main.fxml에

AnchorPane.topAnchor="0.0" 
AnchorPane.bottomAnchor="0.0" 
AnchorPane.leftAnchor="0.0" 
AnchorPane.rightAnchor="0.0" 

과 일했다.