Anton
Anton

Reputation: 1983

How to remove JavaFX stage buttons (minimize, maximize, close)

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

Answers (9)

Joshua
Joshua

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

Shardendu
Shardendu

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

Anderson
Anderson

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

Wesos de Queso
Wesos de Queso

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

Siddhartha Maji
Siddhartha Maji

Reputation: 1052

stage.initStyle(StageStyle.DECORATED);
stage.setResizable(false);

Upvotes: 0

Rostislav Viner
Rostislav Viner

Reputation: 41

stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);

Upvotes: 4

jnr
jnr

Reputation: 237

primaryStage.setResizable(false);

Upvotes: 13

hemisphire
hemisphire

Reputation: 1235

primaryStage.initStyle(StageStyle.UTILITY);

Upvotes: 11

pmoule
pmoule

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

Related Questions