2016-03-11 35 views
1

我有下面的示例代碼FXMLjavafx8調整大小的增長永遠不會收縮

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

<?import javafx.scene.*?> 
<?import javafx.scene.canvas.*?> 
<?import org.cornova.javafx.*?> 
<?import java.lang.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 

<SplitPane dividerPositions="0.5" maxHeight="Infinity" maxWidth="Infinity" minHeight="0" minWidth="0" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.cornova.javafx.PanController"> 
    <items> 
     <HBox prefHeight="246.0" prefWidth="603.0"> 
     <children> 
      <VBox HBox.hgrow="ALWAYS"> 
       <children> 
        <StackPane fx:id="stackPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="165.0" prefWidth="570.0"> 
        <children> 
         <ResizableCanvas fx:id="spectrum" height="195.0" width="573.0" StackPane.alignment="TOP_LEFT" /> 
        </children> 
        </StackPane> 
        <ResizableCanvas fx:id="freqScale" height="10.0" width="570.0" VBox.vgrow="NEVER" /> 
       </children> 
      </VBox> 
      <ResizableCanvas fx:id="dbmScale" height="195.0" width="30.0" HBox.hgrow="NEVER" /> 
     </children> 
     </HBox> 
    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" /> 
    </items> 
</SplitPane> 

我夫婦與以下控制器

/* 
* Here comes the text of your license 
* Each line should be prefixed with * 
*/ 
package org.cornova.javafx; 

/** 
* Sample Skeleton for 'PanView.fxml' Controller Class 
*/ 

import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.fxml.FXML; 
import javafx.scene.layout.StackPane; 
import org.cornova.javafx.ResizableCanvas; 

public class PanController { 

    @FXML // ResourceBundle that was given to the FXMLLoader 
    private ResourceBundle resources; 

    @FXML // URL location of the FXML file that was given to the FXMLLoader 
    private URL location; 

    @FXML // fx:id="stackPane" 
    private StackPane stackPane; // Value injected by FXMLLoader 

    @FXML // fx:id="spectrum" 
    private ResizableCanvas spectrum; // Value injected by FXMLLoader 

    @FXML // fx:id="freqScale" 
    private ResizableCanvas freqScale; // Value injected by FXMLLoader 

    @FXML // fx:id="dbmScale" 
    private ResizableCanvas dbmScale; // Value injected by FXMLLoader 

    @FXML // This method is called by the FXMLLoader when initialization is complete 
    void initialize() { 
     assert stackPane != null : "fx:id=\"stackPane\" was not injected: check your FXML file 'PanView.fxml'."; 
     assert spectrum != null : "fx:id=\"spectrum\" was not injected: check your FXML file 'PanView.fxml'."; 
     assert freqScale != null : "fx:id=\"freqScale\" was not injected: check your FXML file 'PanView.fxml'."; 
     assert dbmScale != null : "fx:id=\"dbmScale\" was not injected: check your FXML file 'PanView.fxml'."; 

     spectrum.widthProperty().bind(stackPane.widthProperty()); 
     spectrum.heightProperty().bind(stackPane.heightProperty()); 
     freqScale.widthProperty().bind(stackPane.widthProperty()); 
     dbmScale.heightProperty().bind(stackPane.heightProperty()); 
     spectrum.widthProperty().addListener((observable, oldValue, newValue) -> { 
      System.out.println("spectrum width changed from " + oldValue + " to " + newValue); 
     }); 
     spectrum.heightProperty().addListener((observable, oldValue, newValue) -> { 
      System.out.println("spectrum height changed from " + oldValue + " to " + newValue); 
     }); 
     freqScale.widthProperty().addListener((observable, oldValue, newValue) -> { 
      System.out.println("Freq scale width changed from " + oldValue + " to " + newValue); 
     }); 
     dbmScale.heightProperty().addListener((observable, oldValue, newValue) -> { 
      System.out.println("dbm scale height changed from " + oldValue + " to " + newValue); 
     }); 

     stackPane.widthProperty().addListener((observable, oldValue, newValue) -> { 
      System.out.println("stackpane width changed from " + oldValue + " to " + newValue); 
     }); 
     stackPane.heightProperty().addListener((observable, oldValue, newValue) -> { 
      System.out.println("stackpane height changed from " + oldValue + " to " + newValue); 
     }); 
    } 
} 

鑑於這兩點,我記得,我的示例應用程序

package org.cornova.portablesdr; 

import java.net.URL; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.control.SplitPane; 
import javafx.scene.layout.Pane; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 

/** 
* 
* @author walt 
*/ 
public class PanadapterView extends Application { 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
     try { 
      URL url = getClass().getResource("/PanView.fxml"); 
      SplitPane root = (SplitPane)FXMLLoader.load(url); 
      Scene scene = new Scene(root, 600,400); 
      primaryStage.setScene(scene); 
      primaryStage.show(); 
     } catch (Exception e) { 
      Logger.getLogger(PanadapterView.class.getName()).log(Level.SEVERE, null, e); 
     } 
    } 

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

工作得非常符合我的預期,除了放大的窗口只有這麼遠,我不能縮小我t,完全可以。我向vbox和hbox添加了一個更改監聽器,它們在增長和縮小方面都能正確執行。

我想要固定在一個軸上的兩個刻度,HBox包含一個VBox和一個可調整的範圍,如FXControl中所述。它有一個固定的寬度,它的高度與stackpane,一個VBox和另一個ResizableCanvas的父級的高度配對。

在當前的fxml文件中,我認爲堆疊面板的寬度看起來很好,我可以將其收縮得很好,但高度永遠不會超過200,這是我不得不用於prefHeight的。但是,它可以覆蓋prefWidth就好了。

在這一點上,我發現自己只是在猜測接下來要改變什麼。我真的一直在試圖研究這個問題..很明顯,沒有運氣。 這是最終的fxml文件。

<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 

<SplitPane dividerPositions="0.5" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0" minWidth="0" orientation="VERTICAL" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.cornova.javafx.PanController"> 
    <items> 
     <HBox fx:id="hbox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0"> 
     <children> 
      <VBox fx:id="vbox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="170.0" prefWidth="570.0" HBox.hgrow="ALWAYS"> 
       <children> 
        <StackPane fx:id="stackPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="570.0"> 
        <children> 
         <ResizableCanvas fx:id="spectrum" /> 
        </children> 
        </StackPane> 
        <ResizableCanvas fx:id="freqScale" height="30.0" width="570.0" VBox.vgrow="NEVER" /> 
       </children> 
      </VBox> 
      <ResizableCanvas fx:id="dbmScale" height="200.0" width="30.0" HBox.hgrow="NEVER" /> 
     </children> 
     </HBox> 
    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" /> 
    </items> 
</SplitPane> 

我希望這一切都有道理。很明顯,我缺少一些東西。

謝謝!

回答

0

答案是Stackpane了(在SceneBuilder)繼承的Vgrow設置,我找不到任何地方解釋,它不會出現在優先級枚舉值。

如果有人會闡明繼承我的目的,並且我確信其他人會讚賞它。

+0

「繼承」在[JavaFX CSS文檔](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typeinherit) –

相關問題