I have the following sample code fxml
<?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>
I couple that with the following controller
/*
* 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);
});
}
}
Given these two, as I recall, my sample app
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();
}
}
worked pretty much as I expected except the enlargement of the window only went so far and I could not shrink it, at all. I added a change listener to the vbox and hbox and they both perform properly with respect to growth and shrinkage.
The two scales I want fixed on one axis, the HBox contains a VBox and a resizableCanvas as described in FXControl. It has a fixed width and its height is paired to the height of the stackpane, a child VBox and parent of another ResizableCanvas.
In the current fxml file I believe the stackpane appear to be fine in width, I can grow and shrink it just fine but the height never exceeds 200, which I was forced to use for prefHeight. It can, however, override prefWidth just fine.
At this point I kind of find myself just guessing at what to change next. I really have been trying to research this issue..so far with no luck, clearly. Here is the final fxml file.
<?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>
I hope this all makes sense. Clearly there is something I am missing.
Thanks!