Answer the question
In order to leave comments, you need to log in
What is the correct way to call a window in Java FX?
Good evening.
Can't figure out what is the gist of calling child windows when using java fx. There is an auxiliary class that should have been responsible for calling the auxiliary window, but when loading () , it always throws an error:
Caused by: java.lang.IllegalStateException: Location is not set.
Here is the method itself:
public class InfoForm {
public void showInfoForm() {
Label secondLabel = new Label("Info");
// StackPane secondaryLayout = new StackPane();
// secondaryLayout.getChildren().add(secondLabel);
FXMLLoader loader = new FXMLLoader(getClass().getResource("test.fxml"));
loader.setRoot(this);
Pane root = null;
try {
root = loader.load();
} catch (IOException e) {
e.printStackTrace();
}
Scene secondScene = new Scene(root, 230, 100);
Stage newWindow = null;
newWindow.setTitle("Second Stage");
newWindow.setScene(secondScene);
newWindow.initModality(Modality.WINDOW_MODAL);
newWindow.show();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.control.Label?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.TextField?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane layoutX="3.0" layoutY="-1.0" prefHeight="200.0" prefWidth="287.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="94.0" minWidth="10.0" prefWidth="69.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="131.0" minWidth="10.0" prefWidth="131.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="73.0" minHeight="10.0" prefHeight="65.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="73.0" minHeight="10.0" prefHeight="65.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="81.0" minHeight="10.0" prefHeight="74.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="67.0" minHeight="10.0" prefHeight="61.0" vgrow="SOMETIMES" />
</rowConstraints>
<opaqueInsets>
<Insets />
</opaqueInsets>
<children>
<Label text="IP/MAC" />
<Label text="Name" GridPane.rowIndex="1" />
<Label text="Сhannel" GridPane.rowIndex="2" />
<Label text="Max.speed" GridPane.rowIndex="3" />
<ComboBox prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField GridPane.columnIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>
</Pane>
Answer the question
In order to leave comments, you need to log in
Try.
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("mainframe.fxml")); //смотрит уже в resources
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(new Scene(fxmlLoader.load(), 1100, 700));
primaryStage.show();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question