Как подгрузить fxml - Java
Формулировка задачи:
Всем привет. Народ подскажите как реализовать данный замысел:
Что должно быть: есть главный fxml в нем есть таблица и хочу в ячейку вставить другой fxml, но перед вставкой необходимо в него внести данные для отображения.
Заранее благодарен.
Вот пример: Simple вставить в head:
Simple.fxml:
Head.xml:
Main.java:
Листинг программы
- <?xml version="1.0" encoding="UTF-8"?>
- <?import javafx.scene.control.Button?>
- <?import javafx.scene.control.TextArea?>
- <?import javafx.scene.layout.Pane?>
- <Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="121.0" prefWidth="282.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
- <children>
- <Button fx:id="btn" layoutX="208.0" layoutY="18.0" mnemonicParsing="false" prefHeight="86.0" prefWidth="52.0" text="Button" />
- <TextArea fx:id="text" layoutX="14.0" layoutY="39.0" prefHeight="44.0" prefWidth="127.0" />
- </children>
- </Pane>
Листинг программы
- <?xml version="1.0" encoding="UTF-8"?>
- <?import javafx.scene.control.SplitPane?>
- <?import javafx.scene.control.TabPane?>
- <?import javafx.scene.layout.AnchorPane?>
- <?import javafx.scene.layout.ColumnConstraints?>
- <?import javafx.scene.layout.GridPane?>
- <?import javafx.scene.layout.RowConstraints?>
- <SplitPane dividerPositions="0.1649048625792812" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" orientation="VERTICAL" prefHeight="475.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
- <items>
- <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
- <children>
- <GridPane fx:id="GridPanelBorde" prefHeight="75.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
- <columnConstraints>
- <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
- </columnConstraints>
- <rowConstraints>
- <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
- </rowConstraints>
- </GridPane>
- </children></AnchorPane>
- <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
- <children>
- <TabPane fx:id="TabPanel1" layoutY="-1.0" prefHeight="372.0" prefWidth="598.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
- </children></AnchorPane>
- </items>
- </SplitPane>
Листинг программы
- package application;
- import javafx.application.Application;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.stage.Stage;
- import javafx.scene.Parent;
- import javafx.scene.control.TabPane;
- import javafx.scene.layout.GridPane;
- import javafx.scene.Scene;
- public class Main extends Application {
- @FXML
- TabPane TabPanel1;
- @FXML
- GridPane GridPanelBorde;
- @Override
- public void start(Stage primaryStage) {
- try {
- Parent root = FXMLLoader.load(getClass().getResource("Head.fxml"));
- Scene scene = new Scene(root);
- scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
- primaryStage.setScene(scene);
- primaryStage.setTitle("Главная");
- primaryStage.show();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Решение задачи: «Как подгрузить fxml»
textual
Листинг программы
- import javafx.application.Application;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.SplitPane;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- public class Main extends Application {
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage primaryStage) {
- try {
- Parent root = FXMLLoader.load(getClass().getResource("head.fxml"));
- SplitPane splitPane = (SplitPane) root.lookup("#split_pane");
- GridPane pane = ((GridPane) splitPane.getItems().get(0).lookup("#grid_pane"));
- Parent simple = FXMLLoader.load(getClass().getResource("simple.fxml"));
- pane.getChildren().add(simple);
- Scene scene = new Scene(root);
- // scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
- primaryStage.setScene(scene);
- primaryStage.setTitle("Главная");
- primaryStage.show();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д