简体   繁体   中英

javafx.fxml.LoadException: StackPane is not a valid type

I need to enclose BorderPane inside StackPane. For using JFXDialog box. The first parameter to JFXDialog() need to be a StackPane variable. I cant able to pass BorderPane variable instead of that. So I tried to create a new StackPane tags around BorderPane

Sample.fxml

<StackPane fx:id="rootPane" xmlns="http://javafx.com/javafx/8.0.112-ea"
    xmlns:fx="http://javafx.com/fxml/1">
    <BorderPane maxHeight="-Infinity" maxWidth="-Infinity"
        minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
        prefWidth="600.0" style="-fx-background-color: #181818;" xmlns="http://javafx.com/javafx/16"
        xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SampleController">
        <left>
          .........
          .........
    </BorderPane>
</StackPane>

But after adding this tag around , Sample.fxml is not opening with SceneBuilder and when I try to run JavaFx Main class I get this error.

javafx.fxml.LoadException: StackPane is not a valid type.

SampleController.java

....
public class SampleController implements Initializable {

...
@FXML
private StackPane rootPane; 

@FXML
    private void migrateButtonAction(ActionEvent event){
        JFXDialogLayout  dialogLayout = new JFXDialogLayout();
        JFXDialog dialog = new JFXDialog(rootPane,dialogLayout, JFXDialog.DialogTransition.TOP);

        if(inputLocationField.getText() == ""){
            JFXButton button = new JFXButton("Okay..I'll Check");
            button.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent mouseEvent) ->{
                dialog.close();
            });

            dialogLayout.setBody(new Text("Please Fill all the text boxes"));
            
        }
    }
}

Most IDEs will add a minimal set of imports when designing. This means that it will explicitly import only the set of layouts that are being used in the form.

When refactoring layouts, one of the most common things to forget is to add imports to the .fxml file in order to support the new layout types.

In this case, the minimal change needed to support StackPane would be to add an import statement:

<?import javafx.scene.layout.StackPane?>

to the import section of the .fxml file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM