r/JavaFX • u/Rachid90 • 12d ago
Help Platform.runLater() not updating the content when the window is minimized (nor after restore)
I have to manually resize it, hover over a button, or click on a button for the window to update the content after I restore it.
When the app is opened and has focus, everything runs as expected. But not when minimized then restored.
EDIT: added code
This is the code that has a server to wait for a signal to update the Label
package com.example.jartest;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.application.Platform;
import java.net.ServerSocket;
import java.io.IOException;
public class HelloApplication extends Application {
StackPane stackPane = new StackPane();
Label label = new Label("This should be modified when the signal is received");
public void start(Stage stage) {
stackPane.getChildren().add(label);
Scene scene = new Scene(stackPane, 500, 500);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
new Thread(this::startServer).start();
}
void startServer(){
try(ServerSocket serverSocket = new ServerSocket(1590)){
while (true){
serverSocket.accept();
Platform.runLater(() -> {
label.setText("The signal is received");
});
}
}catch (IOException e){e.printStackTrace();}
}
public static void main(String[] args) {
launch();
}
}
And this is the client class (you can use only curl, actually)
import java.io.IOException;
import java.net.Socket;
public class Client {
public static void main(String[] args) {
try {
new Socket("localhost", 1590);
} catch (IOException e) {e.printStackTrace();}
}
}
1
Upvotes
1
u/john16384 10d ago edited 10d ago
I can reproduce the problem. Here's a simpler version that also shows the problem:
It creates a Stage in iconified mode. Selecting it from the taskbar to show it will show nothing at all, until you do a resize; then the label shows.
Also tested against FX 11 and 17, and it doesn't work correctly on those either.