If I open another JavaFX (modal) Stage, and set its owner as the original Stage, then the original Stage can't be resized, using the windows drag widget on the bottom right hand corner of the window
I see this in Linux but don't own windows or MacOS so can't test it elsewhere...
here is a minimal example
import javafx.stage.*;
import javafx.scene.*;
import javafx.event.*;
import javafx.application.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
public class HelloWorld extends Application
{
static Stage newStage;
@Override
public void start(Stage primaryStage)
{
Button btn = new Button();
btn.setText("open window");
btn.setOnAction(new EventHandler()
{
@Override
public void handle(ActionEvent event)
{
if (newStage==null)
{
Button newBtn = new Button("Close window");
newBtn.setOnAction(new EventHandler()
{
@Override
public void handle(ActionEvent event)
{
//newStage.hide(); // either or
newStage.close();
}
});
newStage = new Stage();
newStage.initModality(Modality.WINDOW_MODAL);
newStage.initOwner(primaryStage); // BUG doing this, makes main window fixed size
newStage.initStyle(StageStyle.DECORATED);
StackPane newRoot = new StackPane();
newRoot.getChildren().add(newBtn);
Scene newScene = new Scene(newRoot,200,160);
newStage.setScene(newScene);
}
newStage.show();
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
解决方案
This is a confirmed Java bug. Looks like it's targeted for fixing in Java 10 sometime.
That said, I'd love a workaround if someone has one.
Edit: one workaround I've found, ugly as it is, is that you can hide and show the owner stage after hiding the modal child stage. That re-enables resizing. You see the stage disappear and reappear, though, which is messy.