Olá alguém poderia me explicar como funciona o Node no javafx?
Eu estou tentando fazer algo parecido com o cardlayout mas não tou tendo mt sucesso
Se alguém poder me ajudar nisso
meu controller principal:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.market.mercado.main;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
/**
*
* @author Gabriel
*/
public class Controller2 implements Initializable {
@FXML
private Region r1;
@FXML
private Region r2;
@FXML
private Region r0;
@FXML
private Pane stackConsole;
@FXML
private AnchorPane teste1;
@FXML
private AnchorPane teste2;
@FXML
private void btn0(ActionEvent event) {
try {
teste1 = FXMLLoader.load(getClass().getResource("/fxml/Teste.fxml"));
stackConsole.getChildren().addAll(teste1);
System.out.println("xdx");
} catch (IOException ex) {
Logger.getLogger(Controller2.class.getName()).log(Level.SEVERE, null, ex);
}
}
@FXML
private void btn1(ActionEvent event) {
try {
teste2 = FXMLLoader.load(getClass().getResource("/fxml/teste2.fxml"));
stackConsole.getChildren().addAll(teste2);
System.out.println("xd");
} catch (IOException ex) {
Logger.getLogger(Controller2.class.getName()).log(Level.SEVERE, null, ex);
}
}
@FXML
private void btn2(ActionEvent event) {
stackConsole.getChildren().add(teste1);
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
//To change body of generated methods, choose Tools | Templates.
}
}
meu fxml principal;
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.market.mercado.main.Controller2">
<children>
<VBox prefHeight="400.0" prefWidth="100.0">
<children>
<Button mnemonicParsing="false" onAction="#btn0" text="1" />
<Button mnemonicParsing="false" onAction="#btn1" text="2" />
<Button mnemonicParsing="false" onAction="#btn2" text="3" />
</children>
</VBox>
<StackPane fx:id="stackConsole" layoutX="100.0" prefHeight="400.0" prefWidth="500.0">
<children>
<AnchorPane />
</children>
</StackPane>
</children>
</AnchorPane>
fxml teste ::
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" fx:id="teste1" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171" fx:controller="com.market.mercado.main.TesteController">
<children>
<Label layoutX="254.0" layoutY="117.0" text="LABEL 1" />
</children>
</AnchorPane>
teste2 fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" fx:id="teste2" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171" fx:controller="com.market.mercado.main.Teste2Controller">
<children>
<Label layoutX="286.0" layoutY="158.0" text="label3" />
</children>
</AnchorPane>
Quando eu clico no button 1 aparece o label
quando eu clico no button 2 aparece outro label ams não some o antigo: