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

后端 未结 9 1160
你的背包
你的背包 2020-12-05 02:29

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 fo

相关标签:
9条回答
  • 2020-12-05 02:35
    primaryStage.setResizable(false);
    
    0 讨论(0)
  • 2020-12-05 02:35

    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
    
    0 讨论(0)
  • 2020-12-05 02:40

    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.

    0 讨论(0)
  • 2020-12-05 02:42

    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);
    
    0 讨论(0)
  • 2020-12-05 02:42

    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());
    
    0 讨论(0)
  • 2020-12-05 02:56
    primaryStage.initStyle(StageStyle.UTILITY);
    
    0 讨论(0)
提交回复
热议问题