How to bind Pane with another Pane in JavaFX - javafx

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 rectangle) with outer pane (Blue dotted rectangle)
Why I couldn't do it
It seems to be that Pane does not provide bind method for widthProperty
Objects
At least, bind width with TextArea of inner Pane with outer Pane
I'll make many new tabs, therefore, I prefer to bind inner Pane with outer Pane rather than bind TextArea directly to outer Pane.
Situation
Blue and Orange rectangles are bound well with pane dropPane
But Blue border pane's width should be the same size as a red border pane!
My Sources
main.kt:
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.*
import javafx.scene.control.*
import javafx.scene.paint.Paint
import javafx.scene.shape.Rectangle
import javafx.stage.Stage
import javafx.scene.layout.*
import javafx.scene.paint.*
fun main(args : Array<String>) {
println("EntryPoint")
Application.launch(PaneBindingTest().javaClass, *args)
}
class PaneBindingTest : Application() {
private var tabCount = 0
private fun generateNewTab (): Tab {
val tab = Tab()
tabCount += 1
tab.text = "Tab$tabCount"
val fxml = javaClass.getResource("fxml/Tab.fxml")
val aTabPane: Pane = FXMLLoader.load(fxml)
aTabPane.border = Border(BorderStroke(Paint.valueOf("Red"),BorderStrokeStyle.DASHED, CornerRadii.EMPTY, BorderWidths.DEFAULT))
tab.content = aTabPane
return tab
}
override fun start(primaryStage: Stage) {
primaryStage.title = "EntryPoint"
primaryStage.isAlwaysOnTop = true
val fxml = javaClass.getResource("fxml/EntryPoint.fxml")
val root: Parent = FXMLLoader.load(fxml)
val scene = Scene(root)
val epPane= root.lookup("#EPPane") as AnchorPane // Entry Point Pane
val dropPane= root.lookup("#DropPane") as AnchorPane // Drop Pane
val tabPane= root.lookup("#TabPane") as TabPane // Tab Pane
val singleDropPoint= root.lookup("#ForSingle") as Rectangle // Single-ArchiveSet drop point
val multiDropPoint = root.lookup("#ForMulti") as Rectangle // Multi-ArchiveSet drop point
//epPane.background = Background(BackgroundFill(Paint.valueOf("Yellow"), CornerRadii(0.0), Insets(0.0,0.0,0.0,0.0)))
//dropPane.background = Background(BackgroundFill(Paint.valueOf("Green"), CornerRadii(0.0), Insets(0.0,0.0,0.0,0.0)))
tabPane.tabClosingPolicy = TabPane.TabClosingPolicy.ALL_TABS // or SELECTED_TAB, UNAVAILABLE
tabPane.border = Border(BorderStroke(Paint.valueOf("Blue"),BorderStrokeStyle.DASHED, CornerRadii.EMPTY, BorderWidths.DEFAULT))
singleDropPoint.heightProperty().bind(epPane.heightProperty().divide(32).multiply(23))
multiDropPoint.yProperty().bind(singleDropPoint.yProperty().add(dropPane.heightProperty().divide(4).multiply(3)))
multiDropPoint.heightProperty().bind(epPane.heightProperty().divide(4))
primaryStage.scene = scene
primaryStage.show()
val newTab = generateNewTab()
tabPane.tabs.add(newTab)
tabPane.selectionModel.select(newTab)
}
}
fxml/EntryPoint.fxml
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>
<AnchorPane fx:id="EPPane" prefHeight="640.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TabPane fx:id="TabPane" prefHeight="640.0" prefWidth="1152.0" tabClosingPolicy="ALL_TABS" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="128.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
</TabPane>
<AnchorPane fx:id="DropPane" layoutY="128.0" maxWidth="128.0" minWidth="128.0" prefWidth="128.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Rectangle fx:id="ForSingle" arcHeight="16.0" arcWidth="16.0" fill="DODGERBLUE" height="360.0" width="120.0" stroke="#1100ff" strokeType="INSIDE" strokeWidth="8.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="4.0"/>
<Rectangle fx:id="ForMulti" arcHeight="16.0" arcWidth="16.0" fill="#ff9d1f" height="240.0" width="120.0" stroke="#ff8800" strokeType="INSIDE" strokeWidth="8.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.bottomAnchor="4.0"/>
</children>
</AnchorPane>
</children>
</AnchorPane>
fxml/Tab.fxml:
<?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.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" 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">
<children>
<TextArea fx:id="FilePaths" layoutX="4.0" layoutY="80.0" prefHeight="128.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="72.0" />
<RadioButton layoutX="14.0" layoutY="206.0" mnemonicParsing="false" selected="true" text="Hash/Size only">
<toggleGroup>
<ToggleGroup fx:id="AnalyzeMethod" />
</toggleGroup>
</RadioButton>
<RadioButton layoutX="120.0" layoutY="206.0" mnemonicParsing="false" text="FileName" toggleGroup="$AnalyzeMethod" />
<RadioButton layoutX="200.0" layoutY="206.0" mnemonicParsing="false" text="Directory Structure" toggleGroup="$AnalyzeMethod" />
<CheckBox fx:id="CheckDiff" layoutX="336.0" layoutY="206.0" mnemonicParsing="false" text="Show Diff" />
<CheckBox fx:id="CheckSame" layoutX="420.0" layoutY="206.0" mnemonicParsing="false" text="Show Same" />
<ComboBox fx:id="ComboBox" layoutX="840.0" layoutY="202.0" prefWidth="150.0" />
<HBox fx:id="LabelBox" layoutX="12.0" layoutY="14.0" prefHeight="64.0" prefWidth="978.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="4.0" />
</children>
</AnchorPane>
I've found that almost the same question, but no answer was there.

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>

Related

How to make VBox inside of ScrollPane responsive (Chat Application)

I want my Chat Window to be reziable and scrollable, so far everything works except the ChatLog itself.
I need a scroll bar, that's why I put the VBox inside of a ScrollPane (which is child of an AnchorPane), but this way only the ScrollPane is responsive (thanks to Anchor Values). If I unwrap VBox I can set Anchor Values, then it works but I'm loosing my scroll bar.
How can I mantain the scroll bar for ChatLog AND make it responsive (attached on the right side)?
FXML:
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: #5b2529;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.lmu.jungejunkervp.ClientWindowController">
<children>
<ScrollPane fx:id="scrollPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="265.0" prefWidth="592.0" AnchorPane.bottomAnchor="57.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
<content>
<VBox fx:id="chatLog" prefHeight="265.0" prefWidth="575.0" />
</content></ScrollPane>
<TextArea fx:id="messageBox" layoutX="5.0" layoutY="349.0" onKeyPressed="#onEnterSend" prefHeight="47.0" prefWidth="536.0" promptText="enter message..." AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="61.0" />
<Button fx:id="sendButton" mnemonicParsing="false" onAction="#setSendButtonAction" onMouseClicked="#setSendButtonAction" prefHeight="47.0" prefWidth="52.0" text="Send" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="5.0" />
</children>
</AnchorPane>
public void addLabel(String message, Pos position) {
HBox hBox = new HBox();
hBox.setAlignment(position);
hBox.setPadding(new Insets(5, 5, 5, 10));
Text text = new Text(message);
TextFlow textFlow = new TextFlow(text);
textFlow.setStyle("-fx-background-color: rgb(233,233,235);" +
"-fx-background-radius: 20px");
textFlow.setPadding(new Insets(5, 10, 5, 10));
hBox.getChildren().add(textFlow);
Platform.runLater(new Runnable() {
#Override
public void run() {
chatLog.getChildren().add(hBox);
}
});
}
public void setSendButtonAction() {
String message = messageBox.getText().replaceAll("[\n\r]", "");
try {
if (!message.isEmpty()) {
// show message on the sending client window
addLabel(message, Pos.CENTER_RIGHT);
}
}
To answer your actual question, below is what you need add to the ScrollPane (in fxml with your current layout).
fitToHeight="true" fitToWidth="true"
The above code will make your VBox responsive with the ScrollPane.
I also suggest to change your layout to get rid of AnchorPane (will all those hardcoded positions). You can use VBox/HBox in conjuction with vgrow/hgrow policies. The optimized fxml will be as below:
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.HBox?>
<?import javafx.geometry.Insets?>
<VBox style="-fx-background-color: #5b2529;" spacing="5" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.lmu.jungejunkervp.ClientWindowController">
<children>
<ScrollPane fx:id="scrollPane" prefHeight="265.0" prefWidth="592.0" fitToHeight="true" fitToWidth="true" VBox.vgrow="ALWAYS">
<content>
<VBox fx:id="chatLog"/>
</content>
</ScrollPane>
<HBox spacing="5">
<TextArea fx:id="messageBox" onKeyPressed="#onEnterSend" prefHeight="47.0" promptText="enter message..." HBox.hgrow="ALWAYS" />
<Button fx:id="sendButton" mnemonicParsing="false" onAction="#setSendButtonAction" prefHeight="47.0" minWidth="52.0" text="Send"/>
</HBox>
</children>
<padding>
<Insets topRightBottomLeft="5"/>
</padding>
</VBox>
Having said that, I think you need to consider changing your layout to what #jewelsea mentioned in the provided example (using ListView).

fx:script shows NullPointerException in scene builder

I am new with JavaFX FXML and I was trying fx:script with this "NMAESTAGE.fxml" file below:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?language javascript?>
<VBox fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox alignment="CENTER" prefWidth="200.0">
<children>
<Label prefHeight="17.0" prefWidth="83.0" text="Control name:" />
<Region prefHeight="25.0" prefWidth="0.0" HBox.hgrow="ALWAYS" />
<TextField />
</children>
</HBox>
<HBox prefHeight="26.0" prefWidth="228.0">
<children>
<Region HBox.hgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="nextAction()" prefHeight="25.0" prefWidth="53.0" style="-fx-background-radius: 0; -fx-background-color: rgb(0,110,215);" text="Next" textFill="WHITE">
<fx:script>
function nextAction(){
root.getScene().getWindow().hide();
}
</fx:script>
</Button>
</children>
</HBox>
</children>
<padding>
<Insets bottom="30.0" left="30.0" right="30.0" top="50.0" />
</padding>
</VBox>
But the problem is, when I try to open the fxml file in scene builder, the fx:script tag is causing a NullPointerException. It says that "make sure NAMESTAGE.fxml is a valid fxml file".
The application compiles, builds, and runs without any error.
Removing the 5 lines with fx:script tag along with the onAction="nextAction()" part, somehow solve the problem. I don't understand what I am doing wrong here. Could anybody help?
For me it's a bug, introduced by Scene Builder 2.0; the older versione (1.1) doesn't have the problem

JavaFX, and FXML: Centering a Text in HBox

I need some help. How do you center a text in HBox. I am using SceneBuilder. I try and I can't figure it out how to do it.
Here is the code for FXML.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Point3D?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<top>
<HBox prefHeight="50.0" prefWidth="800.0" BorderPane.alignment="CENTER">
<children>
<Text boundsType="LOGICAL_VERTICAL_CENTER" layoutX="600.0" layoutY="600.0" scaleZ="0.0" strokeType="OUTSIDE" strokeWidth="0.0" text="GIANTS DATABASE" textAlignment="CENTER" textOrigin="CENTER" wrappingWidth="231.7841796875" x="600.0" y="600.0">
<rotationAxis>
<Point3D x="1.0" y="1.0" z="1.0" />
</rotationAxis>
</Text>
</children></HBox>
</top>
<right>
<TableView prefHeight="550.0" prefWidth="577.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn minWidth="0.0" prefWidth="72.0" text="Rank" />
<TableColumn editable="false" minWidth="0.0" prefWidth="206.0" text="Name" />
<TableColumn editable="false" minWidth="0.0" prefWidth="88.0" text="Position" />
<TableColumn minWidth="0.0" prefWidth="77.0" text="School" />
<TableColumn minWidth="0.0" prefWidth="66.0" text="Age" />
<TableColumn minWidth="0.0" prefWidth="66.0" text="War" />
</columns>
</TableView>
</right>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="3.0" right="3.0" />
</padding>
The text I want to center is GIANTS DATABASE, under HBox children
Here is the code for javaFX
public class Login extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/giants/LoginF.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("Giants Database Login");
primaryStage.setScene(scene);
primaryStage.show();
}
catch (Exception e) {
}
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Here is the image of the text *GIANTS DATABASE. And I want to center the text where the arrow is pointing**
Remove the bounds, layoutX/Y and rotation settings on the Text node - they are not needed for this. What you are looking for is the HBox alignment property - setting it to Pos.CENTER will layout the children of the HBox in the center both vertically and horizontally. If you want to keep it to the left use Pos.CENTER_LEFT.
It is also not clear from your question whether you wish for the HBox to be this tall - it may be helpful to change the prefHeight of the HBox to Region.USE_COMPUTED_SIZE to have it match the size of the Text note (plus any padding/margins set on either of them).

JavaFX ScrollPane setFitToHeight

since the ListView seems to have some visual bugs when it comes to storing items with a different cell size (resulted in duplicated entries #displaying), I decided to try out a ScrollPane. I replaced the ListView with a ScrollPane with a inner VBox (there are custom HBox stored). So long it's working fine, I dont get any visual bugs any more.
Now I just have a simple problem: As soon the ScrollPane is "full" and starts scrolling, it seems to adjust the size of my "bigger" items.
Here a screen how it looks before the resizing:
Here a screen how it looks when the resize starts:
Here is the fxml of my custom HBox:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<fx:root type="javafx.scene.layout.HBox" fx:id="hboxGridContainer" maxHeight="Infinity" maxWidth="Infinity" prefWidth="580.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" alignment="CENTER_LEFT" styleClass="theme-presets inbox-entry">
<children>
<GridPane fx:id="gridPaneMessages" prefWidth="350.0">
<columnConstraints>
<ColumnConstraints fillWidth="true" hgrow="ALWAYS" />
<ColumnConstraints hgrow="SOMETIMES" />
</columnConstraints>
<rowConstraints>
<RowConstraints fillHeight="true" vgrow="ALWAYS" />
</rowConstraints>
<children>
<HBox fx:id="hboxMessage" alignment="TOP_LEFT" maxHeight="Infinity" minWidth="191.0">
<children>
<Label fx:id="labelMessage" alignment="TOP_LEFT" maxHeight="Infinity" minWidth="191.0" text="blablubkeks" wrapText="true" />
</children>
</HBox>
<AnchorPane GridPane.columnIndex="1">
<children>
<ImageView fx:id="imageViewEncrypted" fitHeight="33.0" fitWidth="33.0" layoutX="43.0" layoutY="-2.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../images/key.png" />
</image>
</ImageView>
<ImageView fx:id="imageViewSigned" fitHeight="42.0" fitWidth="33.0" layoutX="80.0" layoutY="-2.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../images/doublecheck.png" />
</image>
</ImageView>
<Label fx:id="labelTime" layoutX="4.0" layoutY="6.0" prefHeight="17.0" prefWidth="76.0" text="Label" />
</children>
</AnchorPane>
</children>
</GridPane>
</children>
</fx:root>
Here is an extract of my ScrollPane usage in fxml:
<ScrollPane fx:id="scrollPaneChat" layoutX="14.0" layoutY="14.0">
<content>
<VBox fx:id="chatWindowListView" prefHeight="531.0" prefWidth="607.0" />
</content>
</ScrollPane>
The official documentation states, the ScrollPane fitToHeight Property is default on false, which should prevent resizing my HBox's. I want the HBox to stay at it's original height.
Please help me.

JavaFX ScrollPane scrollbar is disabled

I have built a layout in SceneBuilder which has a ScrollPane (inside of a StackPane) containing a StackPane containing a Group (aligned to center-left) containing an ImageView. For some reason, whether I preview within SceneBuilder with Ctrl+P or run in my program, the horizontal scrollbar is disabled. The scrollbar does show that there is more to the right to be scrolled to, but I cannot scroll to it. It looks like this:
And here is the FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Group?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<center>
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: white;" BorderPane.alignment="CENTER">
<children>
<ScrollPane id="scoreScrollPane" fitToHeight="true" hbarPolicy="ALWAYS" prefHeight="0.0" prefWidth="0.0" vbarPolicy="NEVER">
<content>
<StackPane alignment="CENTER_LEFT">
<children>
<Group id="scoreGroup" StackPane.alignment="CENTER_LEFT">
<children>
<ImageView id="scoreImage" fitHeight="150.0" fitWidth="3000.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#Untitled.png" />
</image>
</ImageView>
</children>
</Group>
</children>
</StackPane>
</content>
</ScrollPane>
<HBox id="toolbar" alignment="TOP_CENTER" prefHeight="100.0" prefWidth="200.0" spacing="8.0">
<children>
<Button id="recordButton" mnemonicParsing="false" text="Record" />
<Button id="stopButton" mnemonicParsing="false" text="Stop" />
</children>
<effect>
<DropShadow />
</effect>
</HBox>
</children>
</StackPane>
</center>
</BorderPane>
I've tried a horizontal scroll policy of both AS_NEEDED and ALWAYS.
You have numerous problems (most important is that the HBox with your controls covers your ScrollPane, intercepting that would otherwise go the ScrollPane):
Set preserveRatio="false" instead of preserveRatio="true" for your ImageView, otherwise the image may not grow to the fitWidth you provide (because it may hit the fitHeight limit first and not grow the width anymore).
Set maxHeight="-Infinity" on your HBox, (this will ensure that the maximum height of the HBox does not grow above the preferred height for the HBox, otherwise the HBox will intercept the mouse clicks intended for your ScrollPane). Either this, or set pickOnBounds="false" for the HBox, so that the HBox does not intercept mouse clicks for the ScrollPane even though it overlays the ScrollPane.
Note: to debug layout sizes, sometimes it is useful to temporarily add a background or border to a region to see it's true size, for example style="-fx-background-color: red;".
Also rather than placing your controls and image in a StackPane, which overlays content, maybe you might want to use a VBox instead, which instead lays things out vertically rather than on top of each other.

Resources