Main.class
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
// BorderPane root = new BorderPane();
Parent root = FXMLLoader.load(getClass().getResource("/application/MainWindow.fxml"));
Scene scene = new Scene(root, 400, 400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class MainWindowController {
public void buttonAction(ActionEvent event) {
Stage dialog = new Stage();
dialog.initStyle(StageStyle.TRANSPARENT);
Scene scene = new Scene(new Group(new Text(260, 260, "Hello World!")));
// its Just for checking I want add .fxml here how can I do?
dialog.setScene(scene);
dialog.show();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="400.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainWindowController">
<children>
<Button fx:id="bt1" layoutX="154.0" layoutY="188.0" mnemonicParsing="false" onAction="#buttonAction" text="Login" />
</children>
</AnchorPane>
当我点击登录按钮时,会打开一个包含表单的对话框。 我是怎么做到的我的对话框只包含标题栏上的关闭按钮,当我的对话框打开时,我没有在我的主MAinWindow中执行任何操作。它只显示没有焦点。我怎样才能做到这一点?