How to remove JavaFX stage buttons (minimize, maxi

2019-01-13 18:15发布

问题:

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.

回答1:

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);


回答2:

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.



回答3:

primaryStage.setResizable(false);


回答4:

primaryStage.initStyle(StageStyle.UTILITY);


回答5:

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());


回答6:

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


回答7:

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();
    }


回答8:

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


标签: javafx-2