0

如何在 html 中移动带有标题的未装饰 javafx 窗口?我创建了一个在单击标题时调用的方法,但接下来我应该怎么做?谢谢。

主.java

package sample;

import javafx.application.Application;
import javafx.concurrent.Worker;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import netscape.javascript.JSObject;
import java.io.File;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        WebView webView = new WebView();
        webView.getEngine().setJavaScriptEnabled(true);

        webView.getEngine().getLoadWorker().stateProperty().addListener((observableValue, oldValue, newValue) -> {
            if (newValue == Worker.State.SUCCEEDED) {
                JSObject window = (JSObject) webView.getEngine().executeScript("window");
                window.setMember("_common", new CommonBridge());
            }
        });

        File f = new File("\\index.html");
        webView.getEngine().load(f.toURI().toString());
        VBox vBox = new VBox(webView);
        Scene scene = new Scene(vBox, 750, 400);
        primaryStage.setScene(scene);
        primaryStage.setResizable(false);
        primaryStage.initStyle(StageStyle.UNDECORATED);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

CommonBridge.java

public class CommonBridge {
    public void startDrag() {
        System.out.println("drag started");
    }
}

JavaScript

$("#header").mousedown(function() {
    _common.startDrag();
});
4

0 回答 0