42

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.

César
  • 9,939
  • 6
  • 53
  • 74
Anton
  • 1,903
  • 3
  • 16
  • 18

9 Answers9

82

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);
pdem
  • 3,880
  • 1
  • 24
  • 38
Shardendu
  • 3,480
  • 5
  • 20
  • 28
25

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.

pmoule
  • 4,322
  • 2
  • 34
  • 39
  • 8
    `primaryStage.initStyle(StageStyle.UNDECORATED);` makes a window with no header. How can I remove just the minimize/maximize/close buttons? – Chechulin Jul 22 '13 at 08:42
  • @Chechulin How can I remove just the minimize/maximize/close buttons? There is no option for this now. I tried to remove only minimize for Login. But failed. – Sudhakar Krishnan Feb 21 '17 at 13:47
12
primaryStage.setResizable(false);
Taryn
  • 242,637
  • 56
  • 362
  • 405
jnr
  • 229
  • 2
  • 5
10
primaryStage.initStyle(StageStyle.UTILITY);
hemisphire
  • 1,205
  • 9
  • 19
  • 3
    +1: minimize and maximize buttons removed. Add setOnClose() handler with event.consume() to inhibit close button (workaround). – Aubin Oct 12 '13 at 19:56
  • 1
    Good suggestion @Aubin. However the correct event is `setOnCloseRequest` primaryStage.setOnCloseRequest(new EventHandler() { @Override public void handle(final WindowEvent windowEvent) { windowEvent.consume(); } }); – A J Qarshi Dec 11 '13 at 10:03
  • 2
    Java 8 style: primaryStage.setOnCloseRequest((event) -> event.consume()); – winne2 Dec 18 '14 at 17:00
7

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());
Wesos de Queso
  • 1,526
  • 1
  • 21
  • 23
  • It is consume the event not remove the close button ! – Menai Ala Eddine - Aladdin Mar 21 '18 at 22:08
  • "an undecorated but draggable/titled window (for aesthetic sake) is not possible in javafx at this moment" Has that changed since you wrote this? I'm making a JavaFX app now, and I wish I could edit the Stage itself the same way I can edit the Scene. – qwerty Jul 10 '20 at 19:55
4
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);
1

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();
    }
Anderson
  • 11
  • 2
0
stage.initStyle(StageStyle.DECORATED);
stage.setResizable(false);
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Siddhartha Maji
  • 1,022
  • 8
  • 15
0

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
Joshua
  • 818
  • 11
  • 12