java - 如何使用 javafx 使用 DropDown Items 进行 sidenav?
问题描述
我正在尝试使用可折叠项目制作左侧导航栏,如下所示:
我尝试使用带有按钮的父 Vbox 和另一个带有项目的 vBox 来制作组件。
为了关闭它,我一直在使用缩放动画,但我不知道如何在顶部设置兴趣点,现在我尝试使用平移动画将其翻译,
import com.jfoenix.controls.JFXButton;
import java.util.ArrayList;
import javafx.animation.ScaleTransition;
import javafx.animation.TranslateTransition;
import javafx.geometry.Insets;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
public class SideCollapsableMenu extends VBox{
private VBox vBoxItems;
private JFXButton TopButton;
private TranslateTransition collapseAnimation;
public SideCollapsableMenu(String mainName, ArrayList<JFXButton> buttonList){
this.TopButton = new JFXButton(mainName);
this.vBoxItems = new VBox(0);
this.vBoxItems.setPadding(new Insets(0, 0, 0, 20));
this.vBoxItems.getChildren().addAll(buttonList);
this.getChildren().addAll(TopButton,vBoxItems);
this.TopButton.setOnMouseClicked(event -> playCollapse());
this.collapseAnimation =
new TranslateTransition(Duration.INDEFINITE.millis(1000), vBoxItems);
this.collapseAnimation.setToY(-40*buttonList.size());
}
public void playCollapse(){
collapseAnimation.play();
vBoxItems.setVisible(false);
}
}
但在这两种情况下,下一个项目都不会向上移动。
解决方案
推荐阅读
- html - 无法在html中获取多个复选框的值
- python-3.x - Crontab 没有运行我的脚本(MacOS Catalina 10.15.5)
- c# - C# 使用 ssh.net 从 SSH 服务器检索数据时出错
- reactjs - reactnavigation v5 中的 NavigationActions 替代方案是什么?
- logstash - 通过 http 发送 filebeat 输出
- python - 使运行python shell转储PYC或意外删除的导入模块的源代码?
- api - 该方法在颤振中被调用为null
- html - 可以更改 VBA 资源管理器选择下拉列表的方式吗?
- python - Python - 创建单独的列表,但整数和字符串不起作用
- android - 蓝牙设备搜索在 Android 应用程序中不起作用