Skip to content

JavaFX in Default Window Error on Quit #664

Answered by vsquared
vsquared asked this question in Q&A
Discussion options

You must be logged in to vote

The solution is to get the stage from the default window and then use stage.close().

# Uses Imported mode for py5

import javafx

_wndW = 400
_wndH = 200

def myBtnAction(event):
  global stage
  stage.close()
  
def setup():
  global stage
  
  size(_wndW,_wndH,FX2D)
  get_surface().set_always_on_top(True)
  window_title('JavaFX Round Button in Default Window')
  canvas = get_surface().get_native()
  root = canvas.getParent()
  scene = root.getScene()
  stage = scene.getWindow()
  pane = javafx.scene.layout.Pane()
  root.getChildren().add(pane)
  quitBtn = javafx.scene.control.Button("Q")
  quitBtn.setStyle("-fx-background-radius:5em;"+"-fx-min-width:30px;"+"-fx-min-height:30px;"+"-fx-ma…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@vsquared
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by vsquared
Comment options

You must be logged in to vote
2 replies
@hx2A
Comment options

hx2A Jun 27, 2025
Maintainer

@vsquared
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants