i have a problem with the dialog size. After the program-window, i open another dialogs. The dialogs has a size. This works with Windows, Linux with KDE and older Gnome (Ubuntu 22.04) but not with the actual GNOME (Ubuntu 24.04 or Manjaro). When the comment out lines are active, it works better in actual GNOME but also not always. I have amount of things tryed, but nothing works. Any idea?
This is a sample code with the minimal things to show the problem:
public class Muster extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void init() throws Exception {
}
@Override
public void start(Stage primaryStage) {
show(primaryStage, null, "Dialog 1", false, 500, 500);
show(null, primaryStage, "Dialog 2", false, 400, 400);
show(null, primaryStage, "Dialog 3", false, 400, 400);
}
private static void show(Stage primaryStage, Stage owner, String title, boolean wait, int pos, int size) {
VBox vBox = new VBox();
Label lbl = new Label("Das ist ein Dialog");
Button btn = new Button("Dialog");
btn.setOnAction(a -> show(null, owner, "Wieder einer", true, 600, 600));
vBox.getChildren().add(lbl);
vBox.getChildren().add(btn);
vBox.setAlignment(Pos.CENTER);
try {
Stage stage = primaryStage == null ? new Stage() : primaryStage;
Scene scene = new Scene(vBox, size, size);
stage.setScene(scene);
stage.setTitle(title);
if (owner != null) {
stage.initOwner(owner);
}
stage.setWidth(size);
stage.setHeight(size);
stage.setX(pos);
stage.setY(pos);
// stage.setOnShowing(e -> {
// stage.setWidth(size);
// stage.setHeight(size);
// stage.setX(pos);
// stage.setY(pos);
// });
// stage.setOnShown(e -> {
// stage.setWidth(size);
// stage.setHeight(size);
// stage.setX(pos);
// stage.setY(pos);
// });
stage.setOnCloseRequest(e -> {
System.out.println("closing width: " + stage.getWidth());
System.out.println("closing height: " + stage.getHeight());
System.out.println("closing X: " + stage.getX());
System.out.println("closing Y: " + stage.getY());
});
stage.requestFocus();
stage.toFront();
if (wait) {
stage.showAndWait();
} else {
stage.show();
}
} catch (final Exception exc) {
System.out.println(exc.getMessage());
}
}
}
