29

I am making JavaFX destop application. I want to remove the default windows border and also I want to customize the 3 standard icons of minimize , maximize and close.

The original motivation of this kind of looks or customization is new Kaspersky 2012 User Interface.... I want to design something like that... :)

Dhruv
  • 10,291
  • 18
  • 77
  • 126
  • 6
    How illogical it is to mark a question as duplicate when it actually was the original question. – Haggra Sep 22 '16 at 06:41
  • 4
    If you do design your own window please be very conservative and try to stick somewhat to the design of each native platform. It's incredibly easy to screw it up and make it look like a cheap gimmick. – RecursiveExceptionException Dec 02 '16 at 18:26

1 Answers1

48

This example might be a good starting point. All window decoration is removed. A class extending HBox can be used to place custom buttons for standard window operations.

package javafxdemo;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class JavaDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    class WindowButtons extends HBox {

        public WindowButtons() {
            Button closeBtn = new Button("X");

            closeBtn.setOnAction(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent actionEvent) {
                    Platform.exit();
                }
            });

            this.getChildren().add(closeBtn);
        }
    }

    @Override
    public void start(Stage primaryStage) {
        //remove window decoration
        primaryStage.initStyle(StageStyle.UNDECORATED);

        BorderPane borderPane = new BorderPane();
        borderPane.setStyle("-fx-background-color: green;");

        ToolBar toolBar = new ToolBar();

        int height = 25;
        toolBar.setPrefHeight(height);
        toolBar.setMinHeight(height);
        toolBar.setMaxHeight(height);
        toolBar.getItems().add(new WindowButtons());

        borderPane.setTop(toolBar);

        primaryStage.setScene(new Scene(borderPane, 300, 250));
        primaryStage.show();
    }
}

You can also download the JavaFX Samples where you can find many more useful examples.

pmoule
  • 4,322
  • 2
  • 34
  • 39