Reputation: 1983
How to remove JavaFX stage buttons (minimize, maximize, close)? Can't find any according Stage
methods, so should I use style for the stage? It's necessary for implementing Dialog windows like Error
, Warning
, Info
.
Upvotes: 43
Views: 77395
Reputation: 866
You can achieve this, you call the following methods on your stage object
stage.initModality(Modality.APPLICATION_MODAL); // makes stage act as a modal
stage.setMinWidth(250); // sets stage width
stage.setMinHeight(250); // sets stage height
stage.setResizable(false); // prevents resize and removes minimize and maximize buttons
stage.showAndWait(); // blocks execution until the stage is closed
Upvotes: 0
Reputation: 3590
If you want to disable only the maximize button then use :
stage.resizableProperty().setValue(Boolean.FALSE);
or if u want to disable maximize and minimize except close use
stage.initStyle(StageStyle.UTILITY);
or if you want to remove all three then use
stage.initStyle(StageStyle.UNDECORATED);
Upvotes: 84
Reputation: 11
I found this answer here --> http://javafxportal.blogspot.ie/2012/03/to-remove-javafx-stage-buttons-minimize.html We can do it:
enter code here
@Override
public void start(Stage primaryStage) {
primaryStage.initStyle(StageStyle.UNDECORATED);
Group root = new Group();
Scene scene = new Scene(root, 100, 100);
primaryStage.setScene(scene);
primaryStage.show();
}
Upvotes: 1
Reputation: 1572
I´m having the same issue, seems like an undecorated but draggable/titled window (for aesthetic sake) is not possible in javafx at this moment. The closest approach is to consume the close event.
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
event.consume();
}
});
If you like lambdas
stage.setOnCloseRequest(e->e.consume());
Upvotes: 9
Reputation: 1052
stage.initStyle(StageStyle.DECORATED);
stage.setResizable(false);
Upvotes: 0
Reputation: 41
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);
Upvotes: 4
Reputation: 4352
You just have to set a stage's style. Try this example:
package undecorated;
import javafx.application.Application;
import javafx.stage.StageStyle;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class UndecoratedApp extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.initStyle(StageStyle.UNDECORATED);
Group root = new Group();
Scene scene = new Scene(root, 100, 100);
primaryStage.setScene(scene);
primaryStage.show();
}
}
When learning JavaFX 2.0 these examples are very helpful.
Upvotes: 26