Last active
February 8, 2017 10:00
-
-
Save am4dr/9ee8b3a67db5e37d5626f8c227d301e7 to your computer and use it in GitHub Desktop.
JavaFXでUNDECORATEDなWindowをドラッグで移動する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| JavaFXでUNDECORATEDなウィンドウをドラッグで移動する | |
| 実行: groovy javafx_movable-undeco-window.groovy | |
| */ | |
| import javafx.application.Application | |
| import javafx.scene.Scene | |
| import javafx.scene.control.Label | |
| import javafx.scene.layout.Background | |
| import javafx.scene.layout.BackgroundFill | |
| import javafx.scene.layout.BorderPane | |
| import javafx.scene.layout.Pane | |
| import javafx.scene.paint.Color | |
| import javafx.stage.Stage | |
| import javafx.stage.StageStyle | |
| Application.launch(App, args) | |
| class App extends Application { | |
| @Override | |
| void start(Stage stage) { | |
| def sc = new Scene(pane(stage), 300, 250) | |
| stage.initStyle(StageStyle.UNDECORATED) | |
| stage.scene = sc | |
| stage.show() | |
| } | |
| def pane(window) { | |
| def topPane = new Pane(new Label("Drag here!")) | |
| topPane.background = | |
| new Background(new BackgroundFill(Color.color(0.5, 0.5, 0.5), null, null)) | |
| double pickedX, pickedY | |
| topPane.onMousePressed = { | |
| pickedX = it.sceneX | |
| pickedY = it.sceneY | |
| } | |
| topPane.onMouseDragged = { | |
| window.x = it.screenX - pickedX | |
| window.y = it.screenY - pickedY | |
| } | |
| def pane = new BorderPane() | |
| pane.top = topPane | |
| pane | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment