增加自定义标题栏
This commit is contained in:
parent
4abe8b7a35
commit
105a7fff15
@ -38,6 +38,7 @@ public class LunchApp extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
|
|
||||||
Pane root = new Pane();
|
Pane root = new Pane();
|
||||||
double width = AppConstants.SCREEN_WIDTH;
|
double width = AppConstants.SCREEN_WIDTH;
|
||||||
double length = AppConstants.SCREEN_LENGTH;
|
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());
|
scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/styles.css")).toExternalForm());
|
||||||
initUiComponents();
|
initUiComponents();
|
||||||
UiResourceBundle.bindStringProperty(primaryStage.titleProperty(), TextConstants.TITLE);
|
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.setWidth(width);
|
||||||
primaryStage.setHeight(length);
|
primaryStage.setHeight(length);
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package org.jcnc.jnotepad.view.manager;
|
package org.jcnc.jnotepad.view.manager;
|
||||||
|
|
||||||
|
import javafx.animation.TranslateTransition;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
@ -7,6 +8,12 @@ import javafx.scene.image.Image;
|
|||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import javafx.util.Duration;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 自定义的标题栏,没有完善好,暂时搁置
|
||||||
|
* */
|
||||||
|
|
||||||
|
|
||||||
public class CustomTitleBar extends HBox {
|
public class CustomTitleBar extends HBox {
|
||||||
private static CustomTitleBar instance;
|
private static CustomTitleBar instance;
|
||||||
@ -30,6 +37,7 @@ public class CustomTitleBar extends HBox {
|
|||||||
Button minimizeButton = new Button("-");
|
Button minimizeButton = new Button("-");
|
||||||
minimizeButton.setStyle("-fx-background-color: transparent; ");
|
minimizeButton.setStyle("-fx-background-color: transparent; ");
|
||||||
minimizeButton.setOnAction(event -> {
|
minimizeButton.setOnAction(event -> {
|
||||||
|
|
||||||
Stage stage = (Stage) this.getScene().getWindow();
|
Stage stage = (Stage) this.getScene().getWindow();
|
||||||
stage.setIconified(true); // 最小化窗口
|
stage.setIconified(true); // 最小化窗口
|
||||||
});
|
});
|
||||||
@ -61,6 +69,11 @@ public class CustomTitleBar extends HBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void makeDraggable(Stage stage) {
|
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();
|
final Delta dragDelta = new Delta();
|
||||||
|
|
||||||
// 当鼠标按下时记录初始偏移量
|
// 当鼠标按下时记录初始偏移量
|
||||||
|
|||||||
@ -74,6 +74,7 @@ public class ViewManager {
|
|||||||
|
|
||||||
// 创建主界面布局
|
// 创建主界面布局
|
||||||
root = new BorderPane();
|
root = new BorderPane();
|
||||||
|
//root.setTop(CustomTitleBar.getInstance());
|
||||||
root.setCenter(RootBorderPane.getInstance());
|
root.setCenter(RootBorderPane.getInstance());
|
||||||
|
|
||||||
scene.setRoot(root);
|
scene.setRoot(root);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user