JavaFx: multiple controllers - javafx

I'm working on the project which contains multiple controllers (1 main and two for each of the Fxml files). Unfortunately while running the program, console throw the NullPointerExeption at me. I found out that it's the main controller fault, but still having this information I'm unable to fix this. Could you give me some tips how to solve this issue ?
Here i got the full track:
MainController class:
public class MainController {
#FXML LogInController logInController;
DBConnect dbConnect;
#FXML FlightControlController flightControlController;
#FXML public void initialize() {
logInController.initialize(this);
flightControlController.initialize(this);
dbConnect.initialize(this);
}
}
DBConnect class:
public void dbConnect() throws SQLException {
try {
Conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/nasa", "root", "1234");
} catch(Exception e) {
System.out.println(e.getStackTrace());
}
}
public boolean isCorrect(String login,String password) throws SQLException, IOException {
Stmt = Conn.createStatement();
Rs = Stmt.executeQuery("SELECT * FROM Users WHERE login='"+login+"'AND password='"+password+"';");
if(Rs.next()) {
return true;
} else {
return false;
}
}
public void initialize(MainController mainController) {
this.mainController=mainController;
}
LogInController class:
MainController mainController;
#FXML DBConnect dbConnect;
#FXML TextField logginField = null;
#FXML PasswordField passwordFiled=null;
#FXML Button logInButton;
#FXML
public void buttonClicked(ActionEvent event) throws SQLException, IOException {
mainController.dbConnect.dbConnect();
if(mainController.dbConnect.isCorrect(logginField.getText(),passwordFiled.getText())) {
Parent root = FXMLLoader.load(getClass().getResource("/view/FlightControlView.fxml"));
Scene scene = new Scene(root);
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setScene(scene);
stage.show();
} else {
System.out.print("An error have occured");
}
}
public void initialize(MainController mainController) {
this.mainController=mainController;
}
FlightControlController Class:
#FXML Label label;
MainController mainController;
public void initialize(MainController mainController) {
this.mainController = mainController;
}
And the error which occurs:
Caused by: java.lang.NullPointerException at
controller.LogInController.buttonClicked(LogInController.java:31) ...
62 more
I'm not sure but is it possible that MainController (which doesn't have his own Fxml file) so that FXMLLoader doesn't initialize MainController's properties?
#EDIT
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="693.0" prefWidth="1062.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.LogInController">
<children>
<SplitPane dividerPositions="0.21320754716981133" layoutX="331.0" layoutY="220.0" prefHeight="693.0" prefWidth="1062.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="160.0" prefWidth="100.0">
<children>
<Label alignment="CENTER" layoutY="-1.0" maxHeight="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="70.0" prefWidth="222.0" text="NASA DATABASE" />
<TextField fx:id="logginField" layoutX="18.0" layoutY="101.0" promptText="Login" />
<PasswordField fx:id="passwordFiled" layoutX="18.0" layoutY="165.0" promptText="Password" />
<Button fx:id="logInButton" onAction="#buttonClicked" layoutX="79.0" layoutY="230.0" mnemonicParsing="false" text="Log In" />
</children>
</AnchorPane>
<AnchorPane prefHeight="691.0" prefWidth="493.0" SplitPane.resizableWithParent="false">
<children>
<Label alignment="CENTER" layoutX="97.0" layoutY="104.0" prefHeight="417.0" prefWidth="635.0" text="NOT AVAILABLE, PLEASE LOG IN" AnchorPane.leftAnchor="113.0" AnchorPane.rightAnchor="113.0">
<font>
<Font name="System Bold Italic" size="37.0" />
</font>
</Label>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

Related

Passing a Button in FXML using JavaFX

Hello I Have this portion of my code, I actually need disable the button when the user is logging, I am trying to pass the button to the FXML, but nothing happens: this is the code in the Main Controller, when the user is logged and data match with the password and username the button with the variable btn1 must disabled, I post my entire code for any help.
public Button getBtn1() {
return btn1;
}
public void conexion () {
String usus="";
String Passu ="";
String Bd="jdbc:sqlserver: // THUMANO2:1433;databaseName=QUORA";
String Usuario="sa";
String Pass="milkas87";
String SqlQuery= "select NOMBREUSUARIO, CONVERT (VARCHAR(50), (DecryptByPassPhrase('*xc/6789oÑ---+y',PASS))) as PASS from usuarios where CONVERT (VARCHAR(50), (DecryptByPassPhrase('*xc/6789oÑ---+y',PASS)))='"+fcontrasena.getText().toString().trim()+"'";
Connection Conexion = null;
try {
Conexion=DriverManager.getConnection(Bd, Usuario, Pass);
PreparedStatement ps =Conexion.prepareStatement(SqlQuery);
ResultSet rs = ps.executeQuery();
while(rs.next()) {
usus = rs.getString("NOMBREUSUARIO");
Passu = rs.getString("PASS");
}
if(fcontrasena.getText().toString().trim().equals(Passu) && fusuario.getText().toString().equals(usus)) {
Stage administrador=new Stage();
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Admin.fxml"));
Stage login=(Stage)fusuario.getScene().getWindow();
Parent root = loader.load();
AdminScreenController controlador = loader.<AdminScreenController>getController();
controlador.setBtn1(btn1);
Scene scene=new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
administrador.setScene(scene);
administrador.setTitle("AdminScreen");
login.hide();
administrador.show();
} catch(Exception e) {}
}
} catch(SQLException e) {
JOptionPane.showMessageDialog(null,"error","ERROR",0);
}
}
this is the code for AdminScreenController:
public void setBtn1(Button btn1) {
btn1.setDisable(true);
}
this is the FXML Document:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="576.0" prefWidth="791.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.AdminScreenController">
<children>
<BorderPane fx:id="bpane" prefHeight="621.0" prefWidth="791.0">
<left>
<VBox fx:id="vboxr" prefHeight="576.0" prefWidth="205.0" BorderPane.alignment="CENTER">
<children>
<BorderPane prefHeight="106.0" prefWidth="205.0">
<center>
<Button fx:id="btn1" mnemonicParsing="false" prefHeight="51.0" prefWidth="127.0" text="Planilla Sistemas" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="106.0" prefWidth="205.0">
<center>
<Button fx:id="btn2" mnemonicParsing="false" prefHeight="51.0" prefWidth="127.0" text="AMP" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="116.0" prefWidth="205.0">
<center>
<Button fx:id="btn3" mnemonicParsing="false" prefHeight="51.0" prefWidth="127.0" text="Tareas Funcionarios" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="106.0" prefWidth="205.0">
<center>
<Button fx:id="btn4" mnemonicParsing="false" prefHeight="51.0" prefWidth="127.0" text="Indicadores" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="106.0" prefWidth="205.0" />
</children>
</VBox>
</left>
<top>
<BorderPane prefHeight="145.0" prefWidth="791.0" BorderPane.alignment="CENTER">
<left>
<Pane fx:id="imgview" prefHeight="145.0" prefWidth="205.0" BorderPane.alignment="CENTER" />
</left>
</BorderPane>
</top>
</BorderPane>
</children>
</StackPane>
its something wrong? i need some orientation here. thanks.
Here is an example that shows the MVC relationship in JavaFX. The button is defined in FXML and injected into the controller where it can be accessed.
TestAppView.fxml
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox alignment="CENTER" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.app.TestAppController">
<Button fx:id="myButton" text="Hello World" />
</VBox>
TestAppController.java
public class TestAppController implements Initializable {
#FXML
private Button myButton;
#Override
public void initialize(URL url, ResourceBundle resources) {
// Prints Hello World & disables the button when clicked
myButton.setOnAction((e) -> {
System.out.println("Hello World");
myButton.setDisable(true);
});
}
}
TestAppMain.java
public class TestAppMain extends Application {
#Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(TestAppController.class.getResource("TestAppView.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, 200, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}

Why my ToggleGroup variable is always null?

I defined the following FirstWindow.fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="switcherContainer" layoutX="0.0" layoutY="0.0" prefHeight="170.0" prefWidth="200.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="rep.ButtonController">
<fx:define>
<ToggleGroup fx:id="rType"/>
</fx:define>
<Label layoutX="35.0" layoutY="25.0" prefHeight="17.0" prefWidth="260.0" text="Choose the report type:" />
<RadioButton layoutX="35.0" layoutY="60.0" mnemonicParsing="false" text="A" toggleGroup="$rType" />
<RadioButton layoutX="35.0" layoutY="80.0" mnemonicParsing="false" text="B" toggleGroup="$rType" />
<RadioButton layoutX="35.0" layoutY="100.0" mnemonicParsing="false" text="C" toggleGroup="$rType" />
<RadioButton layoutX="35.0" layoutY="120.0" mnemonicParsing="false" text="D" toggleGroup="$rType" />
</AnchorPane>
I added this FirstWindow.fxml file in Main class:
AnchorPane rootPane = (AnchorPane) FXMLLoader.load(getClass().getResource("/rep/RootScene.fxml"));
primaryStage.setTitle("Report Generation");
primaryStage.setScene(new Scene(rootPane));
AnchorPane innerPane = (AnchorPane) FXMLLoader.load(getClass().getResource("/rep/FirstWindow.fxml"));
rootPane.getChildren().addAll(innerPane);
primaryStage.show();
And my ButtonController class looks like this:
public class ButtonController implements Initializable {
static int step = 0;
#FXML
private Button nextButton;
#FXML
ToggleGroup rType;
#Override
public void initialize(URL location, ResourceBundle resources) {
}
public void onNextButtonClick(ActionEvent event) {
System.out.println("Button Clicked!");
try {
if (rType != null) {
System.out.println("RadioButton selected: " + rType.getSelectedToggle().getUserData().toString());
} else {
System.out.println("rType is null");
}
...
primaryStage.show();
} catch (Exception ex) {
System.out.println("Exception: " + ex);
}
}
}
But I always get the following output in the console:
rType is null
Why? And how to fix it?

How to resize child AnchorPanes within a VBox JavaFX

This is my main UI Main UI
I have a VBox (Fxid:datePane) within a AnchorPane. The Vbox is blue in color.
When the button with the label "Add" is clicked, a "second.fxml" file is loaded into the VBox (Fxid:datePane).
The fxml file loaded takes the height and width of the Vbox.
The second.fxml has a VBox which is red in color.
However if i resize the screen, the loaded file doesn't change its height and width accordingly.
After resizing the screen
How do i make sure the loaded fxml file takes the width and height of its parent VBox (Fxid:datePane) ???
This is my FxmlController.java file
#FXML
private Button btnAdd;
#FXML
private VBox datePane;
#FXML
private VBox vbxsecond;
#FXML
private VBox vbxThird;
#FXML
private AnchorPane apLoader;
VBox v;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
double w = apLoader.getWidth();
double h = apLoader.getHeight();
System.out.println(h);
}
public void setDataPane(Node node) {
// update VBox with new form(FXML) depends on which button is clicked
datePane.getChildren().setAll(node);
}
public VBox fadeAnimate(String url) throws IOException {
v = (VBox) FXMLLoader.load(getClass().getResource(url));
FadeTransition ft = new FadeTransition(Duration.millis(1500));
ft.setNode(v);
ft.setFromValue(0.1);
ft.setToValue(1);
ft.setCycleCount(1);
ft.setAutoReverse(false);
double w = datePane.getWidth();
double h = datePane.getHeight();
v.setPrefHeight(h);
v.setPrefWidth(w);
ft.play();
return v;
}
public void loadPane() throws IOException {
try{
setDataPane(fadeAnimate("/resources/second.fxml"));
}catch(IOException e)
{
e.printStackTrace();
}
}
public void loadPane2 () throws IOException {
try{
setDataPane(fadeAnimate("/resources/third.fxml"));
}catch(IOException e)
{
e.printStackTrace();
}
}
This is my Main.java file
#FXML
private VBox vbxsecond;
#FXML
private VBox datePane;
#Override
public void start(Stage primaryStage) {
try {
//BorderPane root = new BorderPane();
Parent root = FXMLLoader.load(getClass().getResource("/resources/dashboard.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
//primaryStage.setMaximized(true);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
This is my dashboard.fxml file
AnchorPane minHeight="800.0" prefHeight="800.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.FxmlController">
<children>
<SplitPane dividerPositions="0.29797979797979796" layoutX="14.0" layoutY="14.0" prefHeight="800.0" prefWidth="800.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="798.0" prefWidth="192.0">
<children>
<Button fx:id="btnAdd" layoutX="22.0" layoutY="122.0" mnemonicParsing="false" onAction="#loadPane" prefHeight="25.0" prefWidth="51.0" text="Add" AnchorPane.leftAnchor="22.0" AnchorPane.topAnchor="122.0" />
<Button fx:id="btnadd2" layoutX="57.0" layoutY="281.0" mnemonicParsing="false" onAction="#loadPane2" text="ADD second" />
</children>
</AnchorPane>
<AnchorPane fx:id="apLoader" minHeight="0.0" minWidth="0.0" prefHeight="158.0" prefWidth="814.0">
<children>
<VBox fx:id="datePane" layoutX="10.0" layoutY="23.0" prefHeight="798.0" prefWidth="628.0" style="-fx-background-color: Blue;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
This is my second.fxml file
<VBox fx:id="vbxsecond" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="814.0" style="-fx-background-color: Red;" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="vbxSecond" text="HELLOOO" VBox.vgrow="ALWAYS">
<font>
<Font size="96.0" />
</font>
</Label>
</children>
</VBox>
This is my third.fxml file
<VBox fx:id="vbxThird" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="814.0" style="-fx-background-color: Pink;" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="Third HELOO" VBox.vgrow="ALWAYS">
<font>
<Font size="85.0" />
</font>
</Label>
</children>
</VBox>
I solved the problem. I just had to set the values of the VBox in the second.fxml and VBox (Fxid:datePane) in the main.fxml to
AnchorPane.topAnchor="0.0"
AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0"
and it worked.

JAVAFX - Change specific Pane only using 1 window

Can you Help me how to change the Spesific pane in 1 scene.
So when i want to click the Menu A. The Content will change to content A.
And when i click the menu B. The Content will be change to Content B
i try with the 2 FXML and using normal method like load screen A an screen B
But the result only change the window. i want to change the content with 1 window only.
Is there any suggestion how to change the specific pane in 1 window?
As an option.
Make FXML and controller for any "Content" and when the some button is clicked to delete the old "Content" and upload new.
Working example below (edited according to James_D comment):
Main.java
public class Main extends Application {
Parent root;
Stage stage;
#Override
public void start(Stage primaryStage) {
try {
root = FXMLLoader.load(getClass().getResource("Main.fxml"));
stage = primaryStage;
stage.setTitle("Stage");
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<BorderPane fx:id="mainPane" maxHeight="-Infinity" maxWidth="-Infinity" 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="application.Controller">
<left>
<ToolBar orientation="VERTICAL" BorderPane.alignment="CENTER">
<items>
<Button mnemonicParsing="false" onAction="#onBtnAClick" text="A" />
<Button mnemonicParsing="false" onAction="#onBtnBClick" text="B" />
<Button mnemonicParsing="false" onAction="#onBtnCClick" text="C" />
</items>
</ToolBar>
</left>
</BorderPane>
Controller.java
import javafx.fxml.FXML;
import javafx.scene.layout.BorderPane;
public class Controller {
#FXML
BorderPane mainPane;
#FXML
public void onBtnAClick(){
ContentA contentA = new ContentA();
mainPane.setCenter(contentA);
}
#FXML
public void onBtnBClick(){
ContentB contentB = new ContentB();
mainPane.setCenter(contentB);
}
#FXML
public void onBtnCClick(){
ContentC contentC = new ContentC();
mainPane.setCenter(contentC);
}
}
And some sample of Content:
ContentA.java
public class ContentA extends AnchorPane{
public ContentA(){
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ContentA.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
}
}
ContentA.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<fx:root prefHeight="200.0" prefWidth="300.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ListView layoutX="50.0" layoutY="-26.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</fx:root>
try to use this, its easy
Parent root = null;
try {
root=FXMLLoader.load(getClass().getResource("your_FXML_File.fxml"));
} catch (Exception e) {
}
borderpane.setCenter(root);

javafx invoking button to draw rectangle on scene

I am creating a simple application in javafx. The main screen has two tabs and each tab has a button. When (button)btn2 in tab2 is clicked, a rectangle should be displayed on the scene.
Here is my code.
Main class:
public class check extends Application
{
public Stage primaryStage;
private BorderPane rootLayout;
#Override
public void start(Stage primaryStage)
{
this.primaryStage = primaryStage;
this.primaryStage.setTitle("TabsExample");
RootLayout();
}
public void RootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(check.class.getResource("/view/tabs.fxml"));
rootLayout = (BorderPane) loader.load();
primaryStage.setScene(new Scene(rootLayout, 500, 500));
primaryStage.show();
control controller = loader.getController();
} catch (IOException e) {
e.printStackTrace();
}
}
public Stage getPrimaryStage() {
return primaryStage;
}
public static void main(String[] args) {
launch(args);
}
}
Control.java
public class control {
#FXML
private Tab tab1;
#FXML
private Tab tab2;
#FXML
private Button btn1;
#FXML
private Button btn2;
#FXML
private AnchorPane A2;
#FXML
private AnchorPane A1;
public control(){}
private check mainclass;
#FXML public void handleSubmitButtonAction(ActionEvent event)
{
System.out.println("button clicked");
Rectangle r = new Rectangle();
r.setX(50);
r.setY(50);
r.setWidth(200);
r.setHeight(100);
r.setArcWidth(20);
r.setArcHeight(20);
A2.getChildren().add(r);
}
public void setcheck(check ch) {
this.mainclass = ch;
}
}
****FXML:****
<BorderPane maxHeight="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.control">
<top>
<TabPane prefHeight="1754.0" prefWidth="1374.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab id="tab1" text="Draw Circle">
<content>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Button id="btn1" layoutX="23.0" layoutY="44.0" mnemonicParsing="false" text="rectangle" />
</children>
</AnchorPane>
</content></Tab>
<Tab id="tab2" text="Draw Rectangle">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Button id="btn2" layoutX="20.0" layoutY="58.0" mnemonicParsing="false" onAction="#handleSubmitButtonAction" prefHeight="15.0" prefWidth="77.0" text="circle" />
</children></AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</top>
</BorderPane>
I apologize for a very long question. With this code, the button action listener is invoked and the message "Button clicked" is printed on the console. But, I do not understand why the rectangle is not drawn on the screen.
It looks like you're missing the ID for the AnchorPane in your FXML. Also, the appropriate tag to use here is "fx:id". You can read a bit more about that here: What's the difference between fx:id and id: in JavaFX?
Below is the corrected FXML
<BorderPane maxHeight="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.control">
<top>
<TabPane prefHeight="1754.0" prefWidth="1374.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab fx:id="tab1" text="Draw Circle">
<content>
<AnchorPane fx:id="A1" prefHeight="200.0" prefWidth="200.0">
<children>
<Button fx:id="btn1" layoutX="23.0" layoutY="44.0" mnemonicParsing="false" text="rectangle" />
</children>
</AnchorPane>
</content></Tab>
<Tab fx:id="tab2" text="Draw Rectangle">
<content>
<AnchorPane fx:id="A2" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Button fx:id="btn2" layoutX="20.0" layoutY="58.0" mnemonicParsing="false" onAction="#handleSubmitButtonAction" prefHeight="15.0" prefWidth="77.0" text="circle" />
</children></AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</top>
</BorderPane>

Resources