Issues resolving onAction event in JavaFX FXML












0















What should have been straight forward has gone downhill fast.



So far I've tried every onAction related question on stackOverflow, double and triple checked for any typos, and even fell as low as searching on Reddit's /r/javahelp, but alas I have succumbed.



A friend and I are working on a networked text editor as a proof of concept/pet project, and while I am struggling to wrap my head around the networking side of it, I'm trying to be helpful by adding the skin-deep sections, such as this troublesome settings screen. All I want to do is give the user a dialog that allows them to change the theme, which will then load in a new css sheet.



I have the following files:
SettingsTools.java



public class SettingsTools {

String ret = null;
Stage stage;
Parent root;
Scene scene;
SettingsController sc = new SettingsController();

public void changeTheme() {
stage = new Stage();
root = ApplicationTools.loadFromFXML("/fxml/settings.fxml", sc);
scene = new Scene(root, 350, 350);

stage.setScene(scene);
stage.setTitle("Settings");

stage.showAndWait();
}
public String showSettings() {

changeTheme();

return sc.getData();
}
}


settings.fxml



<GridPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.1" >
<columnConstraints>
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
</rowConstraints>
<children>
<RadioButton id="light" selected="true" text="Light">
<toggleGroup>
<ToggleGroup fx:id="t" />
</toggleGroup>
</RadioButton>
<RadioButton id="dark" text="Dark" toggleGroup="$t" GridPane.rowIndex="1" />
<Button text="Accept"
GridPane.columnIndex="1"
GridPane.rowIndex="2"
fx:id="accept"
onAction="#acceptButton"/>
<Button text="Cancel"
GridPane.rowIndex="2"
fx:id="cancel"
onAction="#cancelButton"/>
</children>
</GridPane>


SettingsController.java



public class SettingsController {

String ret = null;
Stage stage;
Parent root;
Scene scene;

@FXML
Button accept;

@FXML
Button cancel;

@FXML
RadioButton dark;

@FXML
RadioButton light;

@FXML
protected void acceptButon() {
if (light.isSelected()) {
ret = "light";
} else if (dark.isSelected()) {
ret = "dark";
}
Stage stage = (Stage) accept.getScene().getWindow();
stage.close();
}

@FXML
protected void cancelButton(ActionEvent event) {
ret = null;
stage.close();
}


public String getData() {
return ret;
}

}


ApplicationTools.java (This is just for reference)



public static <T> T loadFromFXML(String path, Object controller) {
T root;

// Attempt to load FXML file
try {
FXMLLoader loader = new FXMLLoader();
URL location = ApplicationTools.class.getResource(path);
loader.setLocation(location);
if(controller != null) {
loader.setController(controller);
}
root = loader.load();
} catch (Exception e) {
// FXML file load failed, return error scene instead
System.err.format("Failed loading FXML file at path: '%s':n" + e.getMessage(), path);

VBox t_root = new VBox();
t_root.getChildren().add(new Label("Failed loading FXML file at path: '" + path + "':n" + e.getMessage()));

root = (T) t_root;
}

return root;
}


When the user selects that they wish to view the settings screen, a new instance of SettingsTools is created, and then showSettings() is called on it. The whole point of what I'm attempting to achieve at the moment is to return a string based on which option is selected. I know that the whole calling show settings to the call change theme isn't needed, but done this way to limit future changes when more settings are needed.



For some reason, FXML/JavaFX isn't allowing the onAction="acceptButton", but all google answers are all about typos, etc.










share|improve this question


















  • 3





    You have a typo: protected void acceptButon() -> acceptButton()

    – Rcordoval
    Nov 18 '18 at 1:42






  • 3





    You ever have one of those day where no matter how much you try, you always end up in a situation where you just have to "why oh why am I such a god damn fool"? Yeah, me too

    – Setho246
    Nov 18 '18 at 2:58
















0















What should have been straight forward has gone downhill fast.



So far I've tried every onAction related question on stackOverflow, double and triple checked for any typos, and even fell as low as searching on Reddit's /r/javahelp, but alas I have succumbed.



A friend and I are working on a networked text editor as a proof of concept/pet project, and while I am struggling to wrap my head around the networking side of it, I'm trying to be helpful by adding the skin-deep sections, such as this troublesome settings screen. All I want to do is give the user a dialog that allows them to change the theme, which will then load in a new css sheet.



I have the following files:
SettingsTools.java



public class SettingsTools {

String ret = null;
Stage stage;
Parent root;
Scene scene;
SettingsController sc = new SettingsController();

public void changeTheme() {
stage = new Stage();
root = ApplicationTools.loadFromFXML("/fxml/settings.fxml", sc);
scene = new Scene(root, 350, 350);

stage.setScene(scene);
stage.setTitle("Settings");

stage.showAndWait();
}
public String showSettings() {

changeTheme();

return sc.getData();
}
}


settings.fxml



<GridPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.1" >
<columnConstraints>
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
</rowConstraints>
<children>
<RadioButton id="light" selected="true" text="Light">
<toggleGroup>
<ToggleGroup fx:id="t" />
</toggleGroup>
</RadioButton>
<RadioButton id="dark" text="Dark" toggleGroup="$t" GridPane.rowIndex="1" />
<Button text="Accept"
GridPane.columnIndex="1"
GridPane.rowIndex="2"
fx:id="accept"
onAction="#acceptButton"/>
<Button text="Cancel"
GridPane.rowIndex="2"
fx:id="cancel"
onAction="#cancelButton"/>
</children>
</GridPane>


SettingsController.java



public class SettingsController {

String ret = null;
Stage stage;
Parent root;
Scene scene;

@FXML
Button accept;

@FXML
Button cancel;

@FXML
RadioButton dark;

@FXML
RadioButton light;

@FXML
protected void acceptButon() {
if (light.isSelected()) {
ret = "light";
} else if (dark.isSelected()) {
ret = "dark";
}
Stage stage = (Stage) accept.getScene().getWindow();
stage.close();
}

@FXML
protected void cancelButton(ActionEvent event) {
ret = null;
stage.close();
}


public String getData() {
return ret;
}

}


ApplicationTools.java (This is just for reference)



public static <T> T loadFromFXML(String path, Object controller) {
T root;

// Attempt to load FXML file
try {
FXMLLoader loader = new FXMLLoader();
URL location = ApplicationTools.class.getResource(path);
loader.setLocation(location);
if(controller != null) {
loader.setController(controller);
}
root = loader.load();
} catch (Exception e) {
// FXML file load failed, return error scene instead
System.err.format("Failed loading FXML file at path: '%s':n" + e.getMessage(), path);

VBox t_root = new VBox();
t_root.getChildren().add(new Label("Failed loading FXML file at path: '" + path + "':n" + e.getMessage()));

root = (T) t_root;
}

return root;
}


When the user selects that they wish to view the settings screen, a new instance of SettingsTools is created, and then showSettings() is called on it. The whole point of what I'm attempting to achieve at the moment is to return a string based on which option is selected. I know that the whole calling show settings to the call change theme isn't needed, but done this way to limit future changes when more settings are needed.



For some reason, FXML/JavaFX isn't allowing the onAction="acceptButton", but all google answers are all about typos, etc.










share|improve this question


















  • 3





    You have a typo: protected void acceptButon() -> acceptButton()

    – Rcordoval
    Nov 18 '18 at 1:42






  • 3





    You ever have one of those day where no matter how much you try, you always end up in a situation where you just have to "why oh why am I such a god damn fool"? Yeah, me too

    – Setho246
    Nov 18 '18 at 2:58














0












0








0








What should have been straight forward has gone downhill fast.



So far I've tried every onAction related question on stackOverflow, double and triple checked for any typos, and even fell as low as searching on Reddit's /r/javahelp, but alas I have succumbed.



A friend and I are working on a networked text editor as a proof of concept/pet project, and while I am struggling to wrap my head around the networking side of it, I'm trying to be helpful by adding the skin-deep sections, such as this troublesome settings screen. All I want to do is give the user a dialog that allows them to change the theme, which will then load in a new css sheet.



I have the following files:
SettingsTools.java



public class SettingsTools {

String ret = null;
Stage stage;
Parent root;
Scene scene;
SettingsController sc = new SettingsController();

public void changeTheme() {
stage = new Stage();
root = ApplicationTools.loadFromFXML("/fxml/settings.fxml", sc);
scene = new Scene(root, 350, 350);

stage.setScene(scene);
stage.setTitle("Settings");

stage.showAndWait();
}
public String showSettings() {

changeTheme();

return sc.getData();
}
}


settings.fxml



<GridPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.1" >
<columnConstraints>
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
</rowConstraints>
<children>
<RadioButton id="light" selected="true" text="Light">
<toggleGroup>
<ToggleGroup fx:id="t" />
</toggleGroup>
</RadioButton>
<RadioButton id="dark" text="Dark" toggleGroup="$t" GridPane.rowIndex="1" />
<Button text="Accept"
GridPane.columnIndex="1"
GridPane.rowIndex="2"
fx:id="accept"
onAction="#acceptButton"/>
<Button text="Cancel"
GridPane.rowIndex="2"
fx:id="cancel"
onAction="#cancelButton"/>
</children>
</GridPane>


SettingsController.java



public class SettingsController {

String ret = null;
Stage stage;
Parent root;
Scene scene;

@FXML
Button accept;

@FXML
Button cancel;

@FXML
RadioButton dark;

@FXML
RadioButton light;

@FXML
protected void acceptButon() {
if (light.isSelected()) {
ret = "light";
} else if (dark.isSelected()) {
ret = "dark";
}
Stage stage = (Stage) accept.getScene().getWindow();
stage.close();
}

@FXML
protected void cancelButton(ActionEvent event) {
ret = null;
stage.close();
}


public String getData() {
return ret;
}

}


ApplicationTools.java (This is just for reference)



public static <T> T loadFromFXML(String path, Object controller) {
T root;

// Attempt to load FXML file
try {
FXMLLoader loader = new FXMLLoader();
URL location = ApplicationTools.class.getResource(path);
loader.setLocation(location);
if(controller != null) {
loader.setController(controller);
}
root = loader.load();
} catch (Exception e) {
// FXML file load failed, return error scene instead
System.err.format("Failed loading FXML file at path: '%s':n" + e.getMessage(), path);

VBox t_root = new VBox();
t_root.getChildren().add(new Label("Failed loading FXML file at path: '" + path + "':n" + e.getMessage()));

root = (T) t_root;
}

return root;
}


When the user selects that they wish to view the settings screen, a new instance of SettingsTools is created, and then showSettings() is called on it. The whole point of what I'm attempting to achieve at the moment is to return a string based on which option is selected. I know that the whole calling show settings to the call change theme isn't needed, but done this way to limit future changes when more settings are needed.



For some reason, FXML/JavaFX isn't allowing the onAction="acceptButton", but all google answers are all about typos, etc.










share|improve this question














What should have been straight forward has gone downhill fast.



So far I've tried every onAction related question on stackOverflow, double and triple checked for any typos, and even fell as low as searching on Reddit's /r/javahelp, but alas I have succumbed.



A friend and I are working on a networked text editor as a proof of concept/pet project, and while I am struggling to wrap my head around the networking side of it, I'm trying to be helpful by adding the skin-deep sections, such as this troublesome settings screen. All I want to do is give the user a dialog that allows them to change the theme, which will then load in a new css sheet.



I have the following files:
SettingsTools.java



public class SettingsTools {

String ret = null;
Stage stage;
Parent root;
Scene scene;
SettingsController sc = new SettingsController();

public void changeTheme() {
stage = new Stage();
root = ApplicationTools.loadFromFXML("/fxml/settings.fxml", sc);
scene = new Scene(root, 350, 350);

stage.setScene(scene);
stage.setTitle("Settings");

stage.showAndWait();
}
public String showSettings() {

changeTheme();

return sc.getData();
}
}


settings.fxml



<GridPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.1" >
<columnConstraints>
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" />
</rowConstraints>
<children>
<RadioButton id="light" selected="true" text="Light">
<toggleGroup>
<ToggleGroup fx:id="t" />
</toggleGroup>
</RadioButton>
<RadioButton id="dark" text="Dark" toggleGroup="$t" GridPane.rowIndex="1" />
<Button text="Accept"
GridPane.columnIndex="1"
GridPane.rowIndex="2"
fx:id="accept"
onAction="#acceptButton"/>
<Button text="Cancel"
GridPane.rowIndex="2"
fx:id="cancel"
onAction="#cancelButton"/>
</children>
</GridPane>


SettingsController.java



public class SettingsController {

String ret = null;
Stage stage;
Parent root;
Scene scene;

@FXML
Button accept;

@FXML
Button cancel;

@FXML
RadioButton dark;

@FXML
RadioButton light;

@FXML
protected void acceptButon() {
if (light.isSelected()) {
ret = "light";
} else if (dark.isSelected()) {
ret = "dark";
}
Stage stage = (Stage) accept.getScene().getWindow();
stage.close();
}

@FXML
protected void cancelButton(ActionEvent event) {
ret = null;
stage.close();
}


public String getData() {
return ret;
}

}


ApplicationTools.java (This is just for reference)



public static <T> T loadFromFXML(String path, Object controller) {
T root;

// Attempt to load FXML file
try {
FXMLLoader loader = new FXMLLoader();
URL location = ApplicationTools.class.getResource(path);
loader.setLocation(location);
if(controller != null) {
loader.setController(controller);
}
root = loader.load();
} catch (Exception e) {
// FXML file load failed, return error scene instead
System.err.format("Failed loading FXML file at path: '%s':n" + e.getMessage(), path);

VBox t_root = new VBox();
t_root.getChildren().add(new Label("Failed loading FXML file at path: '" + path + "':n" + e.getMessage()));

root = (T) t_root;
}

return root;
}


When the user selects that they wish to view the settings screen, a new instance of SettingsTools is created, and then showSettings() is called on it. The whole point of what I'm attempting to achieve at the moment is to return a string based on which option is selected. I know that the whole calling show settings to the call change theme isn't needed, but done this way to limit future changes when more settings are needed.



For some reason, FXML/JavaFX isn't allowing the onAction="acceptButton", but all google answers are all about typos, etc.







java user-interface javafx fxml






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 1:39









Setho246Setho246

93




93








  • 3





    You have a typo: protected void acceptButon() -> acceptButton()

    – Rcordoval
    Nov 18 '18 at 1:42






  • 3





    You ever have one of those day where no matter how much you try, you always end up in a situation where you just have to "why oh why am I such a god damn fool"? Yeah, me too

    – Setho246
    Nov 18 '18 at 2:58














  • 3





    You have a typo: protected void acceptButon() -> acceptButton()

    – Rcordoval
    Nov 18 '18 at 1:42






  • 3





    You ever have one of those day where no matter how much you try, you always end up in a situation where you just have to "why oh why am I such a god damn fool"? Yeah, me too

    – Setho246
    Nov 18 '18 at 2:58








3




3





You have a typo: protected void acceptButon() -> acceptButton()

– Rcordoval
Nov 18 '18 at 1:42





You have a typo: protected void acceptButon() -> acceptButton()

– Rcordoval
Nov 18 '18 at 1:42




3




3





You ever have one of those day where no matter how much you try, you always end up in a situation where you just have to "why oh why am I such a god damn fool"? Yeah, me too

– Setho246
Nov 18 '18 at 2:58





You ever have one of those day where no matter how much you try, you always end up in a situation where you just have to "why oh why am I such a god damn fool"? Yeah, me too

– Setho246
Nov 18 '18 at 2:58












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357180%2fissues-resolving-onaction-event-in-javafx-fxml%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357180%2fissues-resolving-onaction-event-in-javafx-fxml%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini