<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello,<br>
<br>
we encountered an issue on Linux where resizing the stage while it
is maximized breaks the size of the scene. You can see a video of
this at <a class="moz-txt-link-freetext" href="https://github.com/xpipe-io/xpipe/issues/485">https://github.com/xpipe-io/xpipe/issues/485</a> . The root
cause is that the stage size is modified.<br>
<br>
When doing this, it temporarily or permanently switches to the
size the stage had prior to being maximized, leading to either a
flicker or a permanently broken scene that has the wrong size.
This happens on Gnome and KDE for me with the latest JavaFX ea
version.<br>
<br>
Here is a simple reproducer:</p>
<div style="background-color:#1e1f22;color:#bcbec4">
<pre
style="font-family:'JetBrains Mono',monospace;font-size:9,8pt;">
<span style="color:#cf8e6d;">import </span>javafx.application.Application;
<span style="color:#cf8e6d;">import </span>javafx.scene.Scene;
<span style="color:#cf8e6d;">import </span>javafx.scene.control.Button;
<span style="color:#cf8e6d;">import </span>javafx.scene.layout.Region;
<span style="color:#cf8e6d;">import </span>javafx.scene.layout.StackPane;
<span style="color:#cf8e6d;">import </span>javafx.stage.Stage;
<span style="color:#cf8e6d;">import </span>java.io.IOException;
<span style="color:#cf8e6d;">import </span>java.util.Base64;
<span style="color:#cf8e6d;">public class </span>MaximizeLinuxBug <span
style="color:#cf8e6d;">extends </span>Application {
<span style="color:#b3ae60;">@Override
</span><span style="color:#b3ae60;"> </span><span
style="color:#cf8e6d;">public void </span><span
style="color:#56a8f5;">start</span>(Stage stage) <span
style="color:#cf8e6d;">throws </span>IOException {
Scene scene = <span style="color:#cf8e6d;">new </span>Scene(createContent(), <span
style="color:#2aacb8;">640</span>, <span style="color:#2aacb8;">480</span>);
<span style="color:#cf8e6d;">var </span>s = <span
style="color:#6aab73;"><a class="moz-txt-link-rfc2396E" href="data:text/css;base64,">"data:text/css;base64,"</a> </span>+ Base64.<span
style="font-style:italic;">getEncoder</span>().encodeToString(createCss().getBytes());
scene.getStylesheets().add(s);
stage.setTitle(<span style="color:#6aab73;">"Hello!"</span>);
stage.setScene(scene);
stage.show();
stage.centerOnScreen();
stage.setMaximized(<span style="color:#cf8e6d;">true</span>);
}
<span style="color:#cf8e6d;">private </span>String <span
style="color:#56a8f5;">createCss</span>() {
<span style="color:#cf8e6d;">return </span><span
style="color:#6aab73;">"""
</span><span style="color:#6aab73;"> * {
</span><span style="color:#6aab73;"> -fx-border-color: red;
</span><span style="color:#6aab73;"> -fx-border-width: 1;
</span><span style="color:#6aab73;"> }
</span><span style="color:#6aab73;"> """</span>;
}
<span style="color:#cf8e6d;">private </span>Region <span
style="color:#56a8f5;">createContent</span>() {
<span style="color:#cf8e6d;">var </span>button = <span
style="color:#cf8e6d;">new </span>Button(<span
style="color:#6aab73;">"Click me!"</span>);
button.setOnAction(event -> {
<span style="color:#cf8e6d;">var </span>w = <span
style="color:#c77dbb;">button</span>.getScene().getWindow();
w.setWidth(w.getWidth() - <span style="color:#2aacb8;">1</span>);
event.consume();
});
<span style="color:#cf8e6d;">var </span>stack = <span
style="color:#cf8e6d;">new </span>StackPane(button);
<span style="color:#cf8e6d;">return </span>stack;
}
<span style="color:#cf8e6d;">public static void </span><span
style="color:#56a8f5;">main</span>(String[] args) {
<span style="font-style:italic;">launch</span>();
}
}</pre>
</div>
<p></p>
<p><br>
Best<br>
Christopher Schnick<br>
</p>
</body>
</html>