gpt4 book ai didi

java - javafx 中的动画菜单栏

转载 作者:行者123 更新时间:2023-12-01 22:11:25 25 4
gpt4 key购买 nike

有人有在 javafx 中创建动画菜单栏的经验吗?我需要当鼠标移动到顶部时显示菜单栏,并在鼠标离开此区域(顶部 25px)时隐藏。目前我有一些解决方案,但它看起来不太像我想要的那么漂亮,只是显示/隐藏而不进行任何滑动)))

root.setOnMouseMoved(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getY() < 25){
menuBar.setVisible(true);
root.setTopAnchor(clipPane, 35.0);
} else {
if (menuBar.isVisible()) {
menuBar.setVisible(false);
}

if (menuFile.isShowing()) {
try {
Robot bot = new Robot();
bot.mousePress(InputEvent.BUTTON1_MASK);
bot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (AWTException ex) {
}
}

root.setTopAnchor(clipPane, 0.0);
}
}
});

有人可以帮助提供如何添加显示/隐藏菜单栏滑动效果的信息吗?

最佳答案

经过几个小时的搜索,通过ParallelTransitions自己实现了))

root.setOnMouseMoved(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if ((event.getY() <= 35) && (!fMenuVisible)) {
TranslateTransition clipPane_Slide = new TranslateTransition(Duration.millis(300), clipPane);
clipPane_Slide.setFromY(0);
clipPane_Slide.setToY(35);
clipPane_Slide.setCycleCount(1);
clipPane_Slide.setAutoReverse(false);

TranslateTransition menuBar_Slide = new TranslateTransition(Duration.millis(300), menuBar);
menuBar_Slide.setFromY(0);
menuBar_Slide.setToY(35);
menuBar_Slide.setCycleCount(1);
menuBar_Slide.setAutoReverse(false);

ParallelTransition ShowMenu = new ParallelTransition();
ShowMenu.getChildren().addAll(clipPane_Slide, menuBar_Slide);
ShowMenu.setCycleCount(1);
ShowMenu.playFromStart();

fMenuVisible = true;
} else if ((event.getY() > 35) && (fMenuVisible)) {
TranslateTransition clipPane_Slide = new TranslateTransition(Duration.millis(300), clipPane);
clipPane_Slide.setFromY(35);
clipPane_Slide.setToY(0);
clipPane_Slide.setCycleCount(1);
clipPane_Slide.setAutoReverse(false);

TranslateTransition menuBar_Slide = new TranslateTransition(Duration.millis(300), menuBar);
menuBar_Slide.setFromY(35);
menuBar_Slide.setToY(0);
menuBar_Slide.setCycleCount(1);
menuBar_Slide.setAutoReverse(false);

ParallelTransition HideMenu = new ParallelTransition();
HideMenu.getChildren().addAll(clipPane_Slide, menuBar_Slide);
HideMenu.setCycleCount(1);
HideMenu.playFromStart();

fMenuVisible = false;
}
}
});

关于java - javafx 中的动画菜单栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31748530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com