我正在制作JavaFX destop应用程序。我想删除默认的窗口边框,我也想自定义最小化,最大化和关闭的3个标准图标。JavaFX primaryStage删除窗口边框?
这种长相或定制的原始动机是新的卡巴斯基2012的用户界面....我想设计类似的东西... :)
我正在制作JavaFX destop应用程序。我想删除默认的窗口边框,我也想自定义最小化,最大化和关闭的3个标准图标。JavaFX primaryStage删除窗口边框?
这种长相或定制的原始动机是新的卡巴斯基2012的用户界面....我想设计类似的东西... :)
这个例子可能是一个很好的起点。所有窗户装饰被删除。延伸HBox
的类可用于为标准窗口操作放置自定义按钮。
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 Samples,在那里您可以找到许多更有用的示例。
当问题实际上是原始问题时,将问题标记为重复是多么的不合逻辑。 – Haggra 2016-09-22 06:41:22
如果你确实设计了你自己的窗口,请保守一点,并且试图坚持每个本地平台的设计。这很容易搞砸,使它看起来像一个便宜的噱头。 – RecursiveExceptionException 2016-12-02 18:26:20