JavaFX Transparent Moveable Window #663
                  
                    
                      vsquared
                    
                  
                
                  started this conversation in
                Show and tell
              
            Replies: 2 comments 1 reply
-
| This is really cool! I love the idea of transparent windows. Now we need to figure out how to get the JavaFX drawing surface to be transparent. It would be really neat to be able to draw on a transparent canvas. | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| 
 Is this what you're talking about? Runs on both MacOS and Linux, but doesn't draw on Windows 11 (does allow click-through). Graphics is sharper on Linux than on Mac for some reason. # Uses Imported mode for py5
import javafx
from javafx.scene.paint import *
def myBtnAction(event):
  global stage
  stage.close()
def MOUSE_PRESSED(evnt):
  global gc
  gc.moveTo(evnt.getX(), evnt.getY())
def MOUSE_DRAGGED(evnt):
  global gc,colorPicker
  gc.lineTo( evnt.getX(), evnt.getY())
  gc.stroke()
  gc.setStroke(colorPicker.getValue())
  gc.setLineCap(javafx.scene.shape.StrokeLineCap.ROUND)
  gc.setLineJoin(javafx.scene.shape.StrokeLineJoin.ROUND)
def setup():
  global pane,stage,scene, colorPicker, gc
  size(1, 1, FX2D)
  get_surface().set_visible(False)
  pane = javafx.scene.layout.Pane()
  stage = javafx.stage.Stage()
  scene = javafx.scene.Scene(pane,display_width,display_height)
# Canvas
  canvas = javafx.scene.canvas.Canvas()
  canvas.setLayoutX(0)
  canvas.setLayoutY(0)
  canvas.setWidth(display_width)
  canvas.setHeight(display_height)
  gc = canvas.getGraphicsContext2D()
  gc.setLineWidth(10.0)
  canvas.setOnMousePressed(MOUSE_PRESSED)      
  canvas.setOnMouseDragged(MOUSE_DRAGGED)
  pane.getChildren().add(canvas);
# Color Picker
  colorPicker = javafx.scene.control.ColorPicker(Color.BLUE)
  colorPicker.setLayoutX(60)
  colorPicker.setLayoutY(24)
  pane.getChildren().add(colorPicker)
  
# Quit Button
  btn = javafx.scene.control.Button("Q")
  btn.setStyle("-fx-background-radius:5em;"+"-fx-min-width:30px;"+"-fx-min-height:30px;"+"-fx-max-width:30px;"+"-fx-max-height:30px;")
  btn.setLayoutX(10)
  btn.setLayoutY(24)
  btn.setOnAction(myBtnAction)
  pane.getChildren().add(btn)
  
  stage.setX(0)
  stage.setY(0)
  scene.setFill(None)
  scene.getRoot().setStyle("-fx-background-color: transparent")
  stage.initStyle(javafx.stage.StageStyle.TRANSPARENT);
  stage.setScene(scene)
  stage.setAlwaysOnTop(True)
  stage.show() | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
The following source code will create a moveable transparent window with controls and graphics:
Beta Was this translation helpful? Give feedback.
All reactions