Задать вопрос
  • Почему "положив" класс Controller в другой пакет от fxml, программа отображается не правильно?

    @Aukal Автор вопроса
    Инженер технолог
    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Scene;
    import javafx.scene.layout.Pane;
    import javafx.stage.Stage;
    
    import java.io.IOException;
    
    /**
     * Created by User on 15.04.2016.
     */
    public class AppVeiw  extends Application {
    
    
    
    
        @Override
        public void start(Stage mainStage) throws Exception {
            NavigatorSubWindows navigatorSubWindows = new NavigatorSubWindows();
    
    
            mainStage.setTitle("Sense New");
            mainStage.setScene(createScene(loadMainPane()));
            mainStage.show();
    
    
        }//Закрытие метода Старта
    
    
    
        private Pane loadMainPane() throws IOException {
    
            FXMLLoader loader = new FXMLLoader();
    
            //Pane mainPane = (Pane) loader.load(getClass().getResourceAsStream(NavigatorSubWindows.MENU ));
            Pane mainPane = (Pane) loader.load(getClass().getResource(NavigatorSubWindows.MENU));
    
            MainController control = loader.getController();
    
            NavigatorSubWindows.setMainController(control);
            NavigatorSubWindows.loadWindows(NavigatorSubWindows.HOME);
    
            return mainPane;
        }// Закрытие метода
    
    
        private Scene createScene(Pane mainPane) {
            Scene scene = new Scene( mainPane  );
    
            //scene.getStylesheets().setAll(getClass().getResource("css/vista.css").toExternalForm() );
    
            return scene;
        }// Закрытие метода
    
    
    
     }//  Закрытие класса

    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.scene.Node;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    
    /**
     * Created by User on 15.04.2016.
     */
    public class MainController {
    
        @FXML
        public   StackPane windowsHolder;
    
        public void setWindows  (Node node) {
            windowsHolder.getChildren().setAll(node);
        }
    
        public void openChatWindow(ActionEvent actionEvent) {
            NavigatorSubWindows.loadWindows(NavigatorSubWindows.CHAT);
        }
        @FXML
        Button btnWeb;
        public void openWebWindow(ActionEvent actionEvent) {
            NavigatorSubWindows.loadWindows(NavigatorSubWindows.WEB);
        }
        @FXML
        Button btnHome;
        public void homeWindow(ActionEvent actionEvent) {
            NavigatorSubWindows.loadWindows(NavigatorSubWindows.HOME);
        }
    
        @FXML
        Button btnSearch;
        public void searchContact(ActionEvent actionEvent) {
        }
    
    
    
    
    }


    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.control.*?>
    <?import java.lang.*?>
    <?import javafx.scene.layout.*?>
    
    
    <AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sense.app.controllers.ControllerWeb">
       <children>
          <StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="475.0" prefWidth="517.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
             <children>
                <AnchorPane prefHeight="200.0" prefWidth="200.0">
                   <children>
                      <TextField layoutX="101.0" layoutY="202.0" prefHeight="36.0" prefWidth="198.0" />
                      <Button layoutX="298.0" layoutY="202.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="55.0" text="Search" />
                   </children>
                </AnchorPane>
             </children>
          </StackPane>
       </children>
    </AnchorPane>

    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.geometry.*?>
    <?import javafx.scene.web.*?>
    <?import javafx.scene.control.*?>
    <?import java.lang.*?>
    <?import javafx.scene.layout.*?>
    
    <AnchorPane fx:id="myPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.desktop.raven.azuki.MainController">
       <children>
          <BorderPane layoutX="158.0" layoutY="86.0" prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
             <top>
                <MenuBar BorderPane.alignment="CENTER">
                  <menus>
                    <Menu mnemonicParsing="false" text="File">
                      <items>
                        <MenuItem mnemonicParsing="false" text="Close" />
                      </items>
                    </Menu>
                    <Menu mnemonicParsing="false" text="Edit">
                      <items>
                        <MenuItem mnemonicParsing="false" text="Delete" />
                      </items>
                    </Menu>
                    <Menu mnemonicParsing="false" text="Help">
                      <items>
                        <MenuItem mnemonicParsing="false" text="About" />
                      </items>
                    </Menu>
                  </menus>
                </MenuBar>
             </top>
             <left>
                <SplitPane dividerPositions="0.3276955602536998" orientation="VERTICAL" prefHeight="475.0" prefWidth="283.0" BorderPane.alignment="CENTER">
                  <items>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
                         <children>
                            <VBox layoutX="64.0" layoutY="50.0" prefHeight="315.0" prefWidth="281.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                               <children>
                                  <HBox prefHeight="61.0" prefWidth="281.0">
                                     <children>
                                        <Button fx:id="btnHome" layoutX="134.0" layoutY="10.0" mnemonicParsing="false" onAction="#homeWindow" text="Home">
                                           <HBox.margin>
                                              <Insets bottom="10.0" left="10.0" right="12.0" top="15.0" />
                                           </HBox.margin>
                                        </Button>
                                        <Button fx:id="btnChat" layoutX="15.0" layoutY="25.0" mnemonicParsing="false" onAction="#openChatWindow" text="Chat">
                                           <HBox.margin>
                                              <Insets right="12.0" top="15.0" />
                                           </HBox.margin>
                                        </Button>
                                        <Button fx:id="btnWeb" layoutX="77.0" layoutY="10.0" mnemonicParsing="false" onAction="#openWebWindow" text="Web">
                                           <HBox.margin>
                                              <Insets right="10.0" top="15.0" />
                                           </HBox.margin>
                                        </Button>
                                        <Button fx:id="btnSearch" layoutX="129.0" layoutY="10.0" mnemonicParsing="false" onAction="#searchContact" text="Search">
                                           <HBox.margin>
                                              <Insets bottom="5.0" left="10.0" right="5.0" top="15.0" />
                                           </HBox.margin>
                                        </Button>
                                     </children>
                                  </HBox>
                                  <ListView prefHeight="260.0" prefWidth="281.0" VBox.vgrow="ALWAYS" />
                               </children>
                            </VBox>
                         </children>
                      </AnchorPane>
                  </items>
                </SplitPane>
             </left>
             <center>
                <AnchorPane>
                   <children>
                      <StackPane fx:id="windowsHolder" prefHeight="475.0" prefWidth="517.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" BorderPane.alignment="CENTER" />
                   </children>
                </AnchorPane>
             </center>
          </BorderPane>
       </children>
    </AnchorPane>

    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.control.*?>
    <?import java.lang.*?>
    <?import javafx.scene.layout.*?>
    <AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.desktop.raven.azuki.ControllerHome">
       <children>
          <StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="475.0" prefWidth="517.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
             <children>
                <AnchorPane prefHeight="200.0" prefWidth="200.0">
                   <children>
                      <SplitPane dividerPositions="0.12684989429175475" layoutY="-6.0" orientation="VERTICAL" prefHeight="475.0" prefWidth="517.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                        <items>
                          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
                          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
                               <children>
                                  <ListView layoutX="116.0" layoutY="70.0" prefHeight="410.0" prefWidth="515.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
                               </children>
                            </AnchorPane>
                        </items>
                      </SplitPane>
                   </children>
                </AnchorPane>
             </children>
          </StackPane>
       </children>
    </AnchorPane>
    Ответ написан