N. Navas
N. Navas

Reputation: 41

javafx stage can't be resized after showing a dialog

A JavaFX stage that is originally resizable can't be resized anymore after showing a modal dialog. This only happens in Linux: Ubuntu and XUbuntu. It works fine in Windows.

The code below shows a window with a button. The window initially can be resized without problems. After clicking the button an Alert dialog is shown and after this the window can't be resized anymore. is there something I'm missing here? Is this an Ubuntu bug?

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class StageTest extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Show Alert");
        btn.setOnAction(e -> {
            Alert alert = new Alert(AlertType.WARNING, "This is an alert", ButtonType.YES);
            alert.showAndWait();
        });
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 1000, 850));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Upvotes: 4

Views: 1134

Answers (2)

robodanny
robodanny

Reputation: 96

I can confirm this also happens with RHELS 6.9 using JDK 1.8u192.

The main stage only stops being resizable after the Alert/Dialog is dismissed (hidden).

A workaround is to call alert.initModality(Modality.NONE) before showing. I don't know why this works, but it fixes it for me.

Upvotes: 1

user1585916
user1585916

Reputation: 851

This is a JavaFX bug that occurs when running on linux on a virtual machine. I have the same issue on CentOS 7 when runnning on VMWare using oracle jdk 1.8.0_152.

The bug ticket for this issue is located here: https://bugs.openjdk.java.net/browse/JDK-8140491

The ticket only mentions Ubuntu on Virtual Box, but I have experienced the same issue with CentOS on VMWare.

Unfortunately, the JDK bug system is closed to the public so I cannot vote or watch the issue. Currently, they have been kicking the can down the road and are not planning on fixing this until Java 11! Perhaps if enough people complain they will address this issue sooner.

Upvotes: 2

Related Questions