如果不是这样的话,Javafx窗口会在新阶段获得最大化,如果它处于最大化状态则会恢复

时间:2018-05-21 06:22:11

标签: java javafx

你能不能告诉我这里犯了什么错误这个代码最大化当前窗口,如果不是这样,反之亦然。
这样做是为了刷新表视图,因为在隐藏controlfx的PopOver后,表的刷新不起作用。如果你建议在从PopOver获取价值后重新制作表格内容,那会更好。

public class HomeController implements Initializable {
@FXML
private JFXButton btnViewMedicine;

@FXML
private JFXButton btnAdditional;

@FXML
private GridPane commGridMed;

@FXML
private TabPane tabPane;

@FXML
private Tab tabMedicine;

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    tabPane.getSelectionModel().selectFirst();
    btnViewMedicine.fire();
    tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
        @Override 
        public void changed(ObservableValue<? extends Tab> observable, Tab oldTab, Tab newTab) {
            if(newTab!=null) {
                if(newTab.equals (tabMedicine)) {            
                    btnViewMedicine.fire();
                }
            }
    }
    });
}

@FXML
public void viewMedicine(ActionEvent event) throws IOException {
    GridPane node = (GridPane) FXMLLoader
            .load(getClass().getResource(Constants.VIEW_MEDICINE));
    deleteNode();
    commGridMed.add(node, 0, 1);
}

@FXML
void viewAdditional(ActionEvent event) throws IOException {
    BorderPane node = (BorderPane) FXMLLoader
            .load(getClass().getResource(Constants.VIEW_ADDITIONAL));
    deleteNode();
    commGridMed.add(node, 0, 1);
}

public void viewAdditional() {
    tabPane.getSelectionModel().clearSelection();
    tabPane.getSelectionModel().select(0);
    btnAdditional.fire();
}

public void viewMedicine() {
    tabPane.getSelectionModel().clearSelection();
    tabPane.getSelectionModel().select(0);
    btnViewMedicine.fire();
}

private void deleteNode() {
    Set<Node> deleteNodes = new HashSet<>();
    for (Node child : commGridMed.getChildren()) {
        Integer row = GridPane.getRowIndex(child);
        Integer column = GridPane.getColumnIndex(child);
        if (row != null) {
            if (row.equals(1) && column.equals(0)) {
                deleteNodes.add(child);
            }
        }
    }
    commGridMed.getChildren().removeAll(deleteNodes);
}

}

public class ViewMethods{
public void refresh(MouseEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource(Constants.HOME));
    Parent root = loader.load();
    HomeController controller = (HomeController) loader.getController();
    controller.viewAdditional();
    Scene scene = new Scene(root);
    Stage stage = (Stage((Node)event.getSource()).getScene().getWindow();
    stage.setScene(scene);
    //stage.setMaximized(true);
    stage.show();
}
}

0 个答案:

没有答案