TabPane is not working on my Application

ImperfectLion

I have a project from uni where I have to make an application with Java (in a model view controller format), and I want to make tabs in my application, but it doesn't seem to be working.

I looked up a lot of tutorials, and they all tell me the same way of how to use TabPane, but it doesn't work for me.

Here is the code I have in my Application Loader class:

    package main;

import controller.ModuleChooserController;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;
import model.StudentProfile;
import view.ModuleChooserRootPane;

public class ApplicationLoader extends Application {

    private ModuleChooserRootPane view;

    @Override
    public void init() {
        //create model and view and pass their references to the controller
        StudentProfile model = new StudentProfile();
        view = new ModuleChooserRootPane();
        new ModuleChooserController(view, model);   
    }

    @Override
    public void start(Stage stage) throws Exception {
        //whilst you can set a min width and height (example shown below) for the stage window,
        //you should not set a max width or height and the application should
        //be able to be maximised to fill the screen and ideally behave sensibly when resized
        stage.setMinWidth(530); 
        stage.setMinHeight(500);

        TabPane tabPane = new TabPane();
        Tab tab = new Tab("Testing");
        tabPane.getTabs().add(tab);

        stage.setTitle("Final Year Module Chooser Tool");
        stage.setScene(new Scene(view));
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

}

I have the TabPane implemented, but nothing comes up. I also tried implementing the TabPane in my "view" package, but I had no luck there either.

Here is the code for the ModuleRootChooserPane:

    package view;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;

//You may change this class to extend another type if you wish
public class ModuleChooserRootPane extends BorderPane {

    private ButtonPane bp;
    private ProfileCreator profileCreator;


    public ModuleChooserRootPane() {

        //This sets the colour of background
        this.setStyle("-fx-background-color: #EDF1F3;");

        //Creates a new instance of the buttonPane (Used from ButtonPane.java) and ProfileCreator
        bp = new ButtonPane();
        profileCreator = new ProfileCreator();

        //This adds the padding on the left so that "submit" button is in line with text fields
        bp.setPadding(new Insets(0, 0, 0, 120));

        //Creates a new VBox which adds the ProfileCreator and the button pane
        VBox rootContainer = new VBox(profileCreator, bp);
        rootContainer.setPadding(new Insets(100,100,100,100));


        this.getChildren().add(rootContainer);
    }

}
azro

You choose to work without fxml file, so you need to create your view into the class ModuleChooserRootPane, every graphic element have to be here, or in other classes used here.

So you have to add your TabPane in its constructor too :

public ModuleChooserRootPane() {
    ...
    //this.getChildren().add(rootContainer);
    setLeft(rootContainer);         // or Top/Bottom/Right/Center 


    TabPane tabPane = new TabPane();
    Tab tab = new Tab("Testing");
    tabPane.getTabs().add(tab);
    setCenter(tabPane);             // or Top/Bottom/Right/Left

}

A BorderPane is good idea for root element because it's has several zones to add element, but fo sor you need to use setLeft(), setRight(), setCenter(), setTop() and setBottom() rather than just getChildren().add() where you cannot control the place

enter image description here


Example for adding content in the different tabs :

TabPane tabPane = new TabPane();
Tab tab = new Tab("Testing");
tab.setContent(new VBox(new Label("Here is the testing place"), new Circle(15, 12, 10)));

Tab tab2 = new Tab("Testing2");
HBox hboxContentTab2 = new HBox();
hboxContentTab2.getChildren().add(new Ellipse(10, 10, 10, 13));
hboxContentTab2.getChildren().add(new Label("Here is the BIS testing place"));
tab2.setContent(hboxContentTab2); // add a Node created before, ot can be whatever you wan, borderpane, gridpane, hbox, vbox, label ...

tabPane.getTabs().addAll(tab, tab2);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Dependency not working with my application

From Dev

Pagination not working on my application - CodeIgniter

From Dev

localStorage is working wrong in my application

From Dev

CopyAsync method not working in my application

From Dev

Why is my Spring application working with @RestController but not with @Controller

From Dev

python-eve oplog in not working in my application

From Dev

My work manager is not working after kill the application

From Dev

Props not working in my Vue.js application

From Dev

JavaScript Interface not working in my Android Application

From Dev

How to test Push Notification is working in my application

From Dev

BroadcastReceiver not working when I kill my application

From Dev

cordova plugin permission not working in my application

From Dev

Integrating Google IMA to my application, not working

From Dev

why some photos are not working in my android application

From Dev

Why does my application stop working?

From Dev

Expo application IPA not working on my iphone

From Dev

My camera application not working on kitkat but working on other phones

From Dev

My custom button for my Android Application isnt working

From Java

My application is running and working fully on the Emulator, but crashing on a physical device

From Dev

My require line in application.css.scss isn't working?

From Dev

Loading values from environment variables in my React application not working

From Java

When I press the button back, my application stops working

From Dev

My web application stop working after JSESSIONID appear in URL

From Java

onetoone Mapping is not working in my spring boot rest application and json mysql

From Dev

Task.IsFaulted is not working in my .Net core application

From Dev

componentWillReceiveProps is not working in my react application. It's showing as undefined

From Dev

Windws phone 8:Fast resume is not working in my application

From Dev

array.push method not working for my node.js application

From Dev

Aws elastic beanstalk nginx config is not working for my nodejs web application

Related Related

  1. 1

    Dependency not working with my application

  2. 2

    Pagination not working on my application - CodeIgniter

  3. 3

    localStorage is working wrong in my application

  4. 4

    CopyAsync method not working in my application

  5. 5

    Why is my Spring application working with @RestController but not with @Controller

  6. 6

    python-eve oplog in not working in my application

  7. 7

    My work manager is not working after kill the application

  8. 8

    Props not working in my Vue.js application

  9. 9

    JavaScript Interface not working in my Android Application

  10. 10

    How to test Push Notification is working in my application

  11. 11

    BroadcastReceiver not working when I kill my application

  12. 12

    cordova plugin permission not working in my application

  13. 13

    Integrating Google IMA to my application, not working

  14. 14

    why some photos are not working in my android application

  15. 15

    Why does my application stop working?

  16. 16

    Expo application IPA not working on my iphone

  17. 17

    My camera application not working on kitkat but working on other phones

  18. 18

    My custom button for my Android Application isnt working

  19. 19

    My application is running and working fully on the Emulator, but crashing on a physical device

  20. 20

    My require line in application.css.scss isn't working?

  21. 21

    Loading values from environment variables in my React application not working

  22. 22

    When I press the button back, my application stops working

  23. 23

    My web application stop working after JSESSIONID appear in URL

  24. 24

    onetoone Mapping is not working in my spring boot rest application and json mysql

  25. 25

    Task.IsFaulted is not working in my .Net core application

  26. 26

    componentWillReceiveProps is not working in my react application. It's showing as undefined

  27. 27

    Windws phone 8:Fast resume is not working in my application

  28. 28

    array.push method not working for my node.js application

  29. 29

    Aws elastic beanstalk nginx config is not working for my nodejs web application

HotTag

Archive