import javafx.lang.FX; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.Scene; import javafx.stage.AppletStageExtension; import javafx.stage.Stage; import javafx.stage.StageStyle; // アプレットのパラメータでアプレットで動作しているかどうかを設定する var isApplet = "true".equals(FX.getArgument("isApplet")); Stage { title: "Applet Sample" style: StageStyle.UNDECORATED extensions: [ AppletStageExtension { shouldDragStart: function(event: MouseEvent): Boolean { // ドラッグのキーをカスタマイズする // Ctrlキーとマウスの左ボタンでドラッグさせる return event.controlDown and event.primaryButtonDown; } onAppletRestored: function(): Void { // ブラウザで動作させる時にはタイトルバーを表示しない isApplet = true; } onDragFinished: function(): Void { // ドラッグが終了したらタイトルバーを表示する isApplet = false; } // アプレットの右上の×ボタンを表示しない useDefaultClose: false } ] scene: Scene { width: 300 height: 200 content: [ ImageView { image: Image { url: "{__DIR__}tree.jpg" } }, // タイトルバー TitleBar { // isApplet変数の値によって透明、不透明を設定する opacity: bind if (isApplet) 0.0 else 1.0 } ] } };
import javafx.scene.CustomNode; import javafx.scene.Group; import javafx.scene.input.MouseEvent; import javafx.scene.Node; import javafx.scene.paint.Color; import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Stop; import javafx.scene.Scene; import javafx.scene.shape.Line; import javafx.scene.shape.Rectangle; import javafx.scene.text.Text; public class TitleBar extends CustomNode { public override function create(): Node { Group { content: [ Rectangle { x: 0, y: 0 width: bind scene.width height: 20 fill: LinearGradient { startX: 0.0, startY: 0.0, endX: 1.0, endY: 0.0 proportional: true stops: [ Stop { offset: 0.0 color: Color.GRAY }, Stop { offset: 1.0 color: Color.BLACK } ] } // タイトルバーをドラッグするとステージが移動する onMouseDragged: function(e:MouseEvent):Void { scene.stage.x += e.dragX; scene.stage.y += e.dragY; } }, // タイトルバーにステージのタイトルを表示する Text { x: 5 y: 15 fill: Color.WHITE content: bind scene.stage.title; }, // クローズボタンの外側の四角 Rectangle { x: bind scene.width - 16 y: 4 width: 12 height: 12 fill: Color.BLACK stroke: Color.WHITE onMouseClicked: function( e: MouseEvent ):Void { scene.stage.close(); } }, // クローズボタンの×印 Line { startX: bind scene.width - 16 startY: 4 endX: bind scene.width - 4 endY: 16 strokeWidth: 1 stroke: Color.WHITE }, Line { startX: bind scene.width - 4 startY: 4 endX: bind scene.width - 16 endY: 16 strokeWidth: 1 stroke: Color.WHITE }, ] } } }