I am trying to create a menu for my game using JavaFX. I want to have a "Continue" button that I only want to be visible when a game is running. I'm trying to bind the button's visibility property to a controller, but it doesn't appear to be working- the button is just invisible.
I have looked around Google and StackExchange, and I've found information on how to set it programmatically, but I'd rather not couple the Java code any tighter to the FXML than I really need to.
Here is my code for the FXML page...
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane fx:controller="com.silferein.erq.gui.MenuController"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<padding><Insets top="25" right="25" bottom="25" left="25"/></padding>
<Text id="welcome-text" text="Main Menu" GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="2"/>
<Button text="New" onAction="#handleNew" GridPane.rowIndex="1"/>
<Button text="Continue" onAction="#handleContinue" GridPane.rowIndex="2" visible="${controller.gameRunning}" />
<Button text="Load" onAction="#handleLoad" GridPane.rowIndex="3"/>
<Button text="Save" onAction="#handleSave" GridPane.rowIndex="4"/>
<Button text="Quit" onAction="#handleQuit" GridPane.rowIndex="5"/>
</GridPane>
Here is my code for the controller (trimmed somewhat):
@FXML protected void handleContinue(ActionEvent event) {
System.out.println("Continue!");
parent.handle(new GUIEvent(GUIEvent.Type.CONTINUE));
}
// ...
@FXML protected boolean getGameRunning() {
System.out.println("Test!");
// Some check to see if there's a game in progress...
return true;
}
Any idea what I'm doing wrong? My code compiles and all buttons except "Continue" are visible and working.