Ok guys I have downloaded IssueTrackerLite source code from oracle and have been messing the the fxml in Scene Builder 2.0. 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.

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.

IssueTrackerLite: Download Here

有帮助吗?

解决方案

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.

    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归因
不隶属于 StackOverflow
scroll top