我想装一个新的 fxml
单击按钮时滚动窗格。 RoutinesController
不起作用。当我点击 plusbtn
,我想要 plusaction
要添加的方法 fxml
到滚动窗格。我已经补充了 fxml
在中滚动窗格5次 MakeRoutineController
. 但是在 RoutinesController
, plusaction
不起作用。如何添加新的 fxml
按钮?
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();
// }
//
// }
}
暂无答案!
目前还没有任何答案,快来回答吧!