Created
February 7, 2017 19:38
-
-
Save am4dr/b492e49a49cb40ae3beeaaa4d15096fa to your computer and use it in GitHub Desktop.
JavaFXでUTILITYかつTRANSPARENT(タスクバーにアイコン非表示、ウィンドウ装飾無し、透明)なウィンドウを表示する
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
/* | |
実行は groovy javafx_transparent-utility-window.groovy | |
Windows 10では期待した動作を確認済み | |
次の3点を満たすウィンドウをJavaFXで実現するサンプル | |
- タスクバーにアイコンを表示しない | |
- ウィンドウの装飾がない | |
- 背景が透明 | |
ウィンドウ装飾がないので | |
- 閉じるためのコントロールが必要 | |
- リサイズにもコントロールが必要 | |
- 移動もドラッグ検出などの何かしらの実装が必要 | |
*/ | |
import javafx.application.Application | |
import javafx.application.Platform | |
import javafx.scene.Scene | |
import javafx.scene.control.Button | |
import javafx.scene.layout.Background | |
import javafx.scene.layout.BackgroundFill | |
import javafx.scene.layout.VBox | |
import javafx.scene.paint.Color | |
import javafx.scene.text.Text | |
import javafx.stage.Stage | |
import javafx.stage.StageStyle | |
Application.launch(App, args) | |
class App extends Application { | |
@Override | |
public void start(Stage stage) { | |
stage.with { | |
// UTILITY: 最小限のウィンドウ装飾を持つ、不透明白背景のウィンドウ | |
initStyle(StageStyle.UTILITY) | |
title = "primary stage" | |
// 最小化して画面外に飛ばす | |
maxWidth = 0 | |
maxHeight = 0 | |
x = -100 | |
y = -100 | |
show() | |
} | |
def button = new Button("Close").with { onAction = { Platform.exit() }; it } | |
def transparentBlack = new Background(new BackgroundFill(Color.color(0, 0, 0, 0.5), null, null)) | |
def pane = new VBox(new Text("text"), button).with { background = transparentBlack; it } | |
def tpScene = new Scene(pane, 300, 250).with { fill = Color.TRANSPARENT; it } | |
new Stage().with { | |
initOwner(stage) // UTILITYなstageを親に。 | |
// TRANSPARENT: ウィンドウ装飾がなく、透明な背景を持つウィンドウ | |
initStyle(StageStyle.TRANSPARENT) | |
title = "transparent stage" | |
scene = tpScene | |
show() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment