1 Reply Latest reply on Feb 11, 2013 12:55 PM by 990211

    some questions about how to change scenes

      i have something like the following:

      fxml (view/main/MainMenu.fxml):
      <Scene fx:controller="view.main.CtrlMainMenu" xmlns:fx="http://javafx.com/fxml" stylesheets="view/main/main.css">
          <GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" id="backgorund" hgap="10" vgap="10">
              <!--other panes -->
              <VBox spacing="8" GridPane.columnIndex="0" GridPane.rowIndex="1">
                  <Button text="Start" onAction="#Start"/>
                  <Button text="Options" onAction="#Options"/>
                  <Button text="Exit" onAction="#Exit"/>
      main loop (cotroller/main.java):
      public class main extends Application{
          public static void main(String[] args){
              launch(main.class, args);
          public void start(Stage stage) throws Exception{
              CtrlMainMenu main = new CtrlMainMenu();
              Scene scene = main.main();          //don't know how to make Scene scene = (Scene)FXMLLoader.load(getClass().getResource("MainMenu.fxml")); work on here since MainMenu.fxml is in view/main while the main class is in controller and ended up putting CtrlMainMenu in the view although is not very correct
      view controller (view/main/CtrlMainMenu.java):
      public class CtrlMainMenu{
          //other buttons actions
          public Scene main() throws Exception{
              return (Scene)FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
          @FXML protected void Start(ActionEvent event){
          @FXML protected void Options(ActionEvent event){
          @FXML protected void Exit(ActionEvent event){
              System.exit(0);          //is there any other way to finish the program than using a system.exit?
      got few questions currently:

      1. i'd like to be able to keep using CtrlMainMenu for other buttons while the ones that appear there go to the main (since will be reusing those classes from other scenes)
      tried adding fx:controller on panes instead of the scene, but it doesnt work at all (it crashes) else directly in CtrlMainMenu change the scenes of the stage, but then, i have to send the stage to every controller i use? (or how do i know the stage of the scene?)
      and in the case of options, i'd like after done, go back to the previous scene, is that possible? if so, how?

      2.if i want to implement languages, how do i do to change the text? tried with setText() but depending on where do i put it, it crashes, so dont know where do i have to put it

      3.im doing a game that may have different number of players, so, is there some way to erase/hide/add data from a gridpane with fxml?
        • 1. Re: some questions about how to change scenes
          1. ok, found the way to change scenes, with this way:
          @FXML protected void Start(ActionEvent event) throws Exception{
               Node node = (Node)event.getSource();
               Stage stage = (Stage)node.getScene().getWindow();
               Scene scene = (Scene)FXMLLoader.load(getClass().getResource("../view/main/MainMenu.fxml"));     //this is just an example, will change to go to another scene
          but now i have another problem, when i click on the button the stage scene is changed, but the scene is transformed to a very small one at the top left (the size seems the same as when i dont put the set width/height on the stage when creating it), the stage size remains the same, and when i resize the window, it gets "repaired"

          the options, i thought on using a pane over the current pane so this way instead of going back would be just removing that new pane, would that work well?

          2. found about languages that is by using <Label text="%myText"/> and java.util.ResourceBundle but don't know how to use it, can someone provide me an example, please?

          3. still haven't looked on it...