简体   繁体   English

JavaFX Scene Builder 2.0动态CSS菜单按钮

[英]JavaFX Scene Builder 2.0 dynamic css menubutton

Ok guys I have downloaded IssueTrackerLite source code from oracle and have been messing the the fxml in Scene Builder 2.0 . 好的,我已经从oracle下载了IssueTrackerLite源代码,并弄乱了Scene Builder 2.0fxml I have added a MenuButton with the fx:id of cssTheme and what I want it to do is when the program is check a directory and load all of the css files in that dir into the list, then when you select one it will update the theme/css style on the fly. 我添加了一个菜单按钮与fx:id cssTheme的,我希望它做的是,当该程序是检查目录和加载所有的CSS文件在目录到列表中,那么当你选择一个将更新主题/ css样式。

Kind of vague I know but I am under pressure to learn this very quickly for a client with little to no experience in JavaFX. 我知道有些模糊,但是我迫切需要为几乎没有JavaFX经验的客户快速学习此知识。

IssueTrackerLite: Download Here IssueTrackerLite: 在此处下载

I put this in Application start 我把它放在应用程序开始

    File userPath = new File(System.getProperty("user.dir"));
    for (String s : userPath.list())
        if (s.endsWith(".css")){
            MenuItem mi = new MenuItem(s);
            //using already made menu in my prog
            controller.mnuEdit.getItems().add(mi);
            mi.setOnAction((e)->{
                //always adding and removing from position 1
                //I already have a style sheet set at 0 
                scene.getStylesheets().remove(1);
                try {
                    scene.getStylesheets().add(1,new File(
                            System.getProperty("user.dir")+
                            System.getProperty("file.separator")+s)
                            .toURI().toURL().toExternalForm());
                } catch (MalformedURLException ex) {
                }
            });
        }

Just in case you don't have a ref to controller, I load my fxml like this. 以防万一您没有对控制器的引用,我像这样加载我的fxml。

    try {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setResources(ResourceBundle.getBundle("myprog/language/Base", Locale.getDefault()));
        rootScene = fxmlLoader.load(this.getClass().getResource("Base.fxml").openStream());
        controller = (BaseController) fxmlLoader.getController();
    } catch (IOException ex) {log.severe(ex.getMessage());}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM