Kishirada
Kishirada

Reputation: 152

Hiding and showing a javafx stage without losing data

So I wasn't able to find a topic on this, but it is possible to somehow make a JavaFX stage invisible, but not close / hide the stage.

For instance:

stage.hide()

Will essentially close the stage, making it so that if you want to use:

stage.show()

You'd have to reconstruct the entire stage.

To rephrase:

"Is it possible to make a JavaFX stage invisible and then visible again without losing any data?"

Upvotes: 0

Views: 217

Answers (2)

MMAdams
MMAdams

Reputation: 1498

If you keep a reference to the stage's controller, you can close it and make a new stage using the same controller which has all the same information in it.

Upvotes: 1

Kishirada
Kishirada

Reputation: 152

After some more searching I came across this topic:

JavaFX: can you create a stage that doesn't show on the task bar and is undecorated?

And as it turns out using:

// Note that this is Kotlin
stage.opacity = 0.0
stage.opacity = 1.0

Will make the stage not visible, but retain its information.

Upvotes: 1

Related Questions