JavaFX primaryStage 删除窗口边框? [英] JavaFX primaryStage remove windows borders?
问题描述
我正在制作 JavaFX 停止应用程序.我想删除默认的窗口边框,还想自定义最小化、最大化和关闭 3 个标准图标.
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.
这种外观或定制的最初动机是新的卡巴斯基 2012 用户界面......我想设计这样的东西...... :)
The original motivation of this kind of looks or customization is new Kaspersky 2012 User Interface.... I want to design something like that... :)
推荐答案
这个例子可能是一个很好的起点.所有的窗户装饰都被移除了.扩展 HBox
的类可用于放置用于标准窗口操作的自定义按钮.
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();
}
}
您还可以下载 JavaFX 示例找到更多有用的例子.
You can also download the JavaFX Samples where you can find many more useful examples.
这篇关于JavaFX primaryStage 删除窗口边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!