0
我試圖捕捉X和JavaFX中一個未經修飾窗格的Y座標。該項目使用javafx,JXML和Scene Builder創建。現在還有其他的鏈接提示了答案,但我無法實現它。要麼我得到構建錯誤異常,要麼拿NaN作爲座標。使用以下代碼實現可移動窗格功能所需的最小修改是什麼?移動未裝飾階段的JavaFX與JXML和場景生成器
這裏是MainApp.java(跳過進口,因爲他們是通過NetBeans的處理得非常好)
public class MainApp extends Application {
@Override
public void start(Stage stage) throws Exception {
GridPane MainPane = FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml"));
Scene scene = new Scene(MainPane, Color.TRANSPARENT);
scene.getStylesheets().add("/styles/Styles.css");
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
FXMLController.java
代碼public class FXMLController extends GridPane {
public void rootNodeClick(MouseEvent mouseEvent) {
System.out.println("click");
}
public void rootNodeDrag(MouseEvent mouseEvent) {
System.out.println("drag");
}
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<GridPane fx:id="MainPane" alignment="CENTER" focusTraversable="true" maxHeight="550.0" maxWidth="600.0" minHeight="550.0" minWidth="600.0" nodeOrientation="LEFT_TO_RIGHT" onMouseClicked="#rootNodeClick" onMouseDragged="#rootNodeDrag" prefHeight="550.0" prefWidth="600.0" style="-fx-background-color: #ecf0f1; -fx-background-radius: 3;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="FXMLController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<effect>
<InnerShadow blurType="GAUSSIAN" color="#ffffff44" height="10.0" radius="4.5" width="10.0" />
</effect>
</GridPane>
非常抱歉這指出我正確的方向。謝謝。 – Sam