Skip to content

Instantly share code, notes, and snippets.

@am4dr
Last active February 8, 2017 10:00
Show Gist options
  • Select an option

  • Save am4dr/9ee8b3a67db5e37d5626f8c227d301e7 to your computer and use it in GitHub Desktop.

Select an option

Save am4dr/9ee8b3a67db5e37d5626f8c227d301e7 to your computer and use it in GitHub Desktop.
JavaFXでUNDECORATEDなWindowをドラッグで移動する
/*
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