Reputation: 1111
I have done this...
myStage.initStyle(StageStyle.UTILITY);
which works fine for removing the maximize button but someone can still double click on the window title bar (in Windows) to maximize the window.
I tried this but it does not fire.
myStage.fullScreenProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> prop, Boolean wasIconified, Boolean isIconified) {
System.out.println("ignore fullscreen");
}
});
Is there some other way to consume that event so it has no effect?
Upvotes: 5
Views: 6694
Reputation: 1658
Actually you are listening to the wrong property the one that you are looking for is maximizedProperty
Here is the code to disable window maximize :
primaryStage.maximizedProperty().addListener((observable, oldValue, newValue) -> { if (newValue) primaryStage.setMaximized(false); });
it listens for maximize events then checks whether it's actually maximizing through if (newVale)
then forces the stage disable maximization.
hope it helps
Upvotes: 6
Reputation: 49185
Constraint the stage size ranges
myStage.setMaxHeight(500);
myStage.setMaxWidth(600);
and probably
myStage.setMinHeight(50);
myStage.setMinWidth(60);
EDIT:
Well, I agree with @kleopatra, window maximizing on double-click is a common behavior on most OS GUIs, sooner or later OS users will be familiar with this. Still restricting stage size will be helpful if your layout gets worse on larger/smaller sizes. And also still want to disable double click behavior, build your own window manager with JavaFX (like an Ensemble app) without depending to one that OS provides.
Upvotes: 0
Reputation: 959
If you don't want the user to resize the window at all, you can set the stage's resizable property to false.
Upvotes: 3