title: JavaFX change Pane color from a different class
body: <p>I have a question.
  I want to change the color of a pane from another controller class.
  I am using this code:</p>
  
  <pre><code>FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/Menu.fxml"));
      try {
          Parent loaded = (Parent) loader.load();
      } catch (IOException e) {
          e.printStackTrace();
      }
      MenuController controller = (MenuController) loader.getController();
      Platform.runLater(new Runnable() {
          @Override
          public void run() {
              Pane pane = controller.getRedPane();
              pane.setBackground(new Background(new BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY)));
          }
      });
  </code></pre>
  
  <p>The loaded, controller and pane aren't null.
  But the pane's color doesn't change, can someone help me with this problem?
  Thank you very much.</p>
  
  <p>[EDIT]</p>
  
  <pre><code>public class MenuController implements Initializable
  {
      @FXML
      private GridPane MenuRoot;
  
      @FXML
      private Pane redPane;
  
  
      @Override
      public void initialize(URL location, ResourceBundle resources)
      {
  
      }
  
     @FXML
     private void changeGridSize(ActionEvent event){
         new ChangeSizes();
     }
  
      public GridPane getMenuRoot(){
          return this.MenuRoot;
      }
  
      public Pane getRedPane(){
          return this.redPane;
      }
  }
  </code></pre>
  
  <p>[EDIT]
      </p>
  
  <pre><code>&lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  
  &lt;GridPane fx:id="MenuRoot" gridLinesVisible="true" maxHeight="1.7976931348623157E308"      maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"     fx:controller="nl.voxworks.homeserver.client.MenuController"&gt;
    &lt;columnConstraints&gt;
    &lt;ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="0.0" percentWidth="50.0" /&gt;
    &lt;ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="0.0" percentWidth="50.0" /&gt;
    &lt;/columnConstraints&gt;
    &lt;rowConstraints&gt;
      &lt;RowConstraints maxHeight="1.7976931348623157E308" minHeight="0.0" percentHeight="50.0" vgrow="ALWAYS" /&gt;
      &lt;RowConstraints maxHeight="1.7976931348623157E308" minHeight="0.0" percentHeight="50.0" vgrow="ALWAYS" /&gt;
      &lt;/rowConstraints&gt;
     &lt;children&gt;
        &lt;Pane fx:id="redPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: red;" GridPane.rowIndex="1" /&gt;
        &lt;Pane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;" GridPane.columnIndex="1" GridPane.rowIndex="1" /&gt;
     &lt;/children&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>[EDIT] (different project all files included)
      package javafxapplication16;</p>
  
  <pre><code>import java.io.IOException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javafx.application.Platform;
  import javafx.fxml.FXMLLoader;
  import javafx.geometry.Insets;
  import javafx.scene.layout.Background;
  import javafx.scene.layout.BackgroundFill;
  import javafx.scene.layout.CornerRadii;
  import javafx.scene.layout.Pane; 
  import javafx.scene.paint.Color;
  
  public class ChangeSize {
  
  public ChangeSize(){
      FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
      try {
          loader.load();
      } catch (IOException ex) {
          Logger.getLogger(ChangeSize.class.getName()).log(Level.SEVERE, null, ex);
      }
      FXMLDocumentController controller = (FXMLDocumentController) loader.getController();
  
      Platform.runLater(new Runnable() {
          @Override
          public void run() {
               Pane pane = controller.getPane();
              pane.setBackground(new Background(new BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY)));
          }
      });
      }
  }
  </code></pre>
  
  <p>FXMLDocumentController.</p>
  
  <pre><code>package javafxapplication16;
  
  import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.control.Label;
  import javafx.scene.layout.Pane;
  
  public class FXMLDocumentController implements Initializable {
  
  @FXML
  private Pane redPane;
  
  @FXML
  private void changeGridSize(ActionEvent event){
      new ChangeSize();
  }
  
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
  
  }    
  
  public Pane getPane(){
      return this.redPane;
  }
  }
  </code></pre>
  
  <p>JavaFXApplication16</p>
  
  <pre><code>package javafxapplication16;
  
  import java.io.IOException;
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  
  public class JavaFXApplication16 extends Application {
  
  @Override
  public void start(Stage stage) throws Exception {
    //  Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
     // FXMLLoader loader
  
      Parent loaded=null;
      FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
      try {
          loaded = (Parent) loader.load();
      } catch (IOException e) {
          e.printStackTrace();
      }
      Scene scene = new Scene(loaded);
  
      stage.setScene(scene);
      stage.show();       
  }
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      launch(args);
  }
  }
  </code></pre>
  
  <p>FXML
      </p>
  
  <pre><code>&lt;?import java.lang.*?&gt;
  &lt;?import java.util.*?&gt;
  &lt;?import javafx.scene.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  
  &lt;GridPane fx:id="MenuRoot" gridLinesVisible="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication16.FXMLDocumentController"&gt;
    &lt;columnConstraints&gt;
    &lt;ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="0.0" percentWidth="50.0" /&gt;
    &lt;ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="0.0" percentWidth="50.0" /&gt;
    &lt;/columnConstraints&gt;
     &lt;rowConstraints&gt;
      &lt;RowConstraints maxHeight="1.7976931348623157E308" minHeight="0.0" percentHeight="50.0" vgrow="ALWAYS" /&gt;
      &lt;RowConstraints maxHeight="1.7976931348623157E308" minHeight="0.0" percentHeight="50.0" vgrow="ALWAYS" /&gt;
      &lt;/rowConstraints&gt;
      &lt;children&gt;
        &lt;Pane fx:id="redPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: red;" GridPane.rowIndex="1" /&gt;
        &lt;Pane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;" GridPane.columnIndex="1" GridPane.rowIndex="1" /&gt;
        &lt;Button mnemonicParsing="false" onAction="#changeGridSize" text="Button" /&gt;
     &lt;/children&gt;
  &lt;/GridPane&gt;
  </code></pre>