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

匿名 (未验证) 提交于 2019-12-03 01:52:01

问题:

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:

stage.setOnCloseRequest(new EventHandler() {                 @Override                 public void handle(WindowEvent event) {                     event.consume();                 }             }); 

If you like lambdas

stage.setOnCloseRequest(e->e.consume()); 


回答6:

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


回答7:

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


回答8:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!