增加自定义标题栏
This commit is contained in:
parent
4abe8b7a35
commit
105a7fff15
@ -38,6 +38,7 @@ public class LunchApp extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
|
||||
Pane root = new Pane();
|
||||
double width = AppConstants.SCREEN_WIDTH;
|
||||
double length = AppConstants.SCREEN_LENGTH;
|
||||
@ -46,6 +47,14 @@ public class LunchApp extends Application {
|
||||
scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/styles.css")).toExternalForm());
|
||||
initUiComponents();
|
||||
UiResourceBundle.bindStringProperty(primaryStage.titleProperty(), TextConstants.TITLE);
|
||||
|
||||
/* // 获取自定义标题栏的实例并添加到BorderPane的顶部
|
||||
CustomTitleBar customTitleBar = CustomTitleBar.getInstance();
|
||||
// 使自定义标题栏可拖动
|
||||
customTitleBar.makeDraggable(primaryStage);*/
|
||||
// primaryStage.initStyle(StageStyle.UNDECORATED); // 移除默认窗口装饰
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setWidth(width);
|
||||
primaryStage.setHeight(length);
|
||||
primaryStage.setScene(scene);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package org.jcnc.jnotepad.view.manager;
|
||||
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
@ -7,6 +8,12 @@ import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
|
||||
/*
|
||||
* 自定义的标题栏,没有完善好,暂时搁置
|
||||
* */
|
||||
|
||||
|
||||
public class CustomTitleBar extends HBox {
|
||||
private static CustomTitleBar instance;
|
||||
@ -30,6 +37,7 @@ public class CustomTitleBar extends HBox {
|
||||
Button minimizeButton = new Button("-");
|
||||
minimizeButton.setStyle("-fx-background-color: transparent; ");
|
||||
minimizeButton.setOnAction(event -> {
|
||||
|
||||
Stage stage = (Stage) this.getScene().getWindow();
|
||||
stage.setIconified(true); // 最小化窗口
|
||||
});
|
||||
@ -61,6 +69,11 @@ public class CustomTitleBar extends HBox {
|
||||
}
|
||||
|
||||
public void makeDraggable(Stage stage) {
|
||||
|
||||
// 创建一个平移动画,设置持续时间和目标位置
|
||||
TranslateTransition minimizeAnimation = new TranslateTransition(Duration.seconds(0.3), stage.getScene().getRoot());
|
||||
minimizeAnimation.setToY(stage.getHeight()); // 将根节点向下平移,使窗口消失
|
||||
|
||||
final Delta dragDelta = new Delta();
|
||||
|
||||
// 当鼠标按下时记录初始偏移量
|
||||
@ -79,4 +92,4 @@ public class CustomTitleBar extends HBox {
|
||||
private static class Delta {
|
||||
double x, y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,6 +74,7 @@ public class ViewManager {
|
||||
|
||||
// 创建主界面布局
|
||||
root = new BorderPane();
|
||||
//root.setTop(CustomTitleBar.getInstance());
|
||||
root.setCenter(RootBorderPane.getInstance());
|
||||
|
||||
scene.setRoot(root);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user