2016-04-15 44 views
0

FXML(JavaFX)でユーザーがサイズ変更した後に新しいウィンドウサイズを取得するにはどうすればよいですか?私は "onResizeWindow"メソッドを検索しましたが、何も見つかりませんでした。FXML(JavaFX)でウィンドウのサイズを変更

私は単純なPaneを持っており、ユーザーがウィンドウのサイズを変更したときにサイズを変更したいと思っています。そして、ツールバーをペインでどのようにサイズ変更しますか?ここで

は私のFXMLコードです:

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1" fx:controller="testJavaFXML.Controller"> 
    <padding> 
     <Insets bottom="200.0" left="200.0" right="200.0" top="200.0" /> 
    </padding> 
    <children> 
     <ToolBar prefWidth="600.0"> 
     <items> 
      <Button fx:id="buttonPlay" mnemonicParsing="false" onAction="#handlePlayButtonAction" text="Play" /> 
      <Button fx:id="buttonPause" mnemonicParsing="false" onAction="#handlePauseButtonAction" text="Pause" /> 
      <Button fx:id="buttonStop" mnemonicParsing="false" onAction="#handleStopButtonAction" text="Stop" /> 
     </items> 
     </ToolBar> 
     <Label fx:id="labelHelloWorld" layoutX="250.0" layoutY="187.0" text="Hello World!" /> 
    </children> 
</Pane> 

私はこれを行う方法が見つかりました:私はそのように、Paneを含んStackPaneを使用する必要があります。

<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
     <Pane prefHeight="200.0" prefWidth="200.0"> 
     <children> 
      <ToolBar prefWidth="600.0"> 
       <items> 
        <Button fx:id="buttonPlay" mnemonicParsing="false" onAction="#handlePlayButtonAction" text="Play" /> 
        <Button fx:id="buttonPause" mnemonicParsing="false" onAction="#handlePauseButtonAction" text="Pause" /> 
        <Button fx:id="buttonStop" mnemonicParsing="false" onAction="#handleStopButtonAction" text="Stop" /> 
       </items> 
      </ToolBar> 
     </children> 
     </Pane> 
     <Label fx:id="labelHelloWorld" text="Hello World!" /> 
    </children> 
</StackPane> 

答えて

0

あなたが幅を聴くことができますステージの高さ:

stage.widthProperty().addListener((ov, oldWidth, newWidth) -> someAction); 

しかし、より良いアプローチは、例えば適切なレイアウトパネル。サイズ変更を処理するBorderPane

関連する問題