当我的框架设置为未装饰时,如何使JAVAFX中的Anchorpane可拖动?
这是我在view类中的代码。当我的框架设置为未装饰时,如何使JAVAFX中的Anchorpane可拖动?,java,javafx,Java,Javafx,这是我在view类中的代码。 这只是导入 package View; import javafx.application.Application; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.scene.layo
这只是导入
package View;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import java.awt.*;
不要介意我的sql方法
import static SQL.MySQL.connectDB;
这是我的JavaFX
框架。请记住,我使用FXML scenebuilder
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("design.fxml"));
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setScene(new Scene(root, (screenSize.getWidth()/2), screenSize.getHeight()/2));
primaryStage.show();
}
public static void main(String[] args)
{
connectDB();
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("design.fxml"));
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setScene(new Scene(root, (screenSize.getWidth()/2), screenSize.getHeight()/2));
primaryStage.show();
}
public static void main(String[] args)
{
connectDB();
launch(args);
}
public class Client extends Application {
private double offset_x;
private double offset_y;
private static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("design.fxml"));
Scene scene = new Scene(root, (screenSize.getWidth()/2), screenSize.getHeight()/2);
scene.setOnMousePressed(event -> {
offset_x = event.getSceneX();
offset_y = event.getSceneY();
});
scene.setOnMouseDragged(event -> {
primaryStage.setX(event.getScreenX() - offset_x);
primaryStage.setY(event.getScreenY() - offset_y);
});
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}