2

I want to load a new fxml to scroll pane when I click a button. RoutinesController does not work. When I click plusbtn, I want the plusaction method to add fxml to the scroll pane. I already added fxml 5 times to the scroll pane in MakeRoutineController. But in RoutinesController, plusaction does not work. How can I add a new fxml button?

package HealthSchedule.controller;


import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import com.jfoenix.controls.JFXButton;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;

public class RoutinesController extends MakeRoutineController  implements Initializable{

    @FXML JFXButton plusbtn;
    @FXML AnchorPane home;
    
    public RoutinesController() {
        this.column = super.column;
        this.row = super.row;
    }
    
    
    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        
    }
    public void plusaction(ActionEvent event) {
        
        try {
            
                FXMLLoader fxmlLoader = new FXMLLoader();
                fxmlLoader.setLocation(getClass().getResource("/HealthSchedule/resources/routines.fxml"));
                AnchorPane anchorPane = fxmlLoader.load();
                
                if(column == 1) {
                    column = 0;
                    row++;
                }
                
                super.grid.add(anchorPane, column++, row);
                  //set grid width
                super.grid.setMinWidth(Region.USE_COMPUTED_SIZE);
                super. grid.setPrefWidth(Region.USE_COMPUTED_SIZE);
                super.grid.setMaxWidth(Region.USE_PREF_SIZE);

                //set grid height
                super.grid.setMinHeight(Region.USE_COMPUTED_SIZE);
                super.grid.setPrefHeight(Region.USE_COMPUTED_SIZE);
                super.grid.setMaxHeight(Region.USE_PREF_SIZE);
                
                GridPane.setMargin(anchorPane, new Insets(10));
            
        } catch (Exception e) {
            // TODO: handle exception
        }

        
    
    
    }

    
}

package HealthSchedule.controller;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXScrollPane;

import javafx.animation.FadeTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;
import javafx.util.Duration;

public class MakeRoutineController implements Initializable{


    @FXML ScrollPane scroll;
    @FXML GridPane grid;
//  @FXML JFXButton plusbtn;
    int column = 0;
    int row = 1;
    
    
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        
        
        
        try {
            for(int i = 0; i< 5; i++) {
                FXMLLoader fxmlLoader = new FXMLLoader();
                fxmlLoader.setLocation(getClass().getResource("/HealthSchedule/resources/routines.fxml"));
                AnchorPane anchorPane = fxmlLoader.load();
                
                if(column == 1) {
                    column = 0;
                    row++;
                }
                
                grid.add(anchorPane, column++, row);
                  //set grid width
                grid.setMinWidth(Region.USE_COMPUTED_SIZE);
                grid.setPrefWidth(Region.USE_COMPUTED_SIZE);
                grid.setMaxWidth(Region.USE_PREF_SIZE);

                //set grid height
                grid.setMinHeight(Region.USE_COMPUTED_SIZE);
                grid.setPrefHeight(Region.USE_COMPUTED_SIZE);
                grid.setMaxHeight(Region.USE_PREF_SIZE);
                
                GridPane.setMargin(anchorPane, new Insets(10));
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        
//      createPage();
        
        
        
        
        
        
    }
//  private void createPage() {
//      try {
//          AnchorPane newanchor = FXMLLoader.load(getClass().getResource("/HealthSchedule/resources/routines.fxml"));
//          grid.add(newanchor,0,0);
//      } catch (IOException e) {
//          // TODO Auto-generated catch block
//          e.printStackTrace();
//      }
//      
//  }

    
    

}
Kirby
  • 15,127
  • 10
  • 89
  • 104
lallabblla
  • 21
  • 1

0 Answers0