Creating JavaFX app with Material Design

So. I'm using my own Material Design inspired library for developing with JavaFX. There's already one out there, but it uses FXML. I prefer doing everything on code, since, it seems Oracle dropped support for the FXML app some time ago (could have been re-supported by now, but I don't know).

I started making this library since July last year, but I haven't worked on it actively. However, I have it working good for what I've needed so far. For making a simple Material-like layout, I simply write something like this in the JavaFX's start method:

Code:
@Override
    public void start(Stage primaryStage) {
        
        StackPane root=new StackPane();
        
        MaterialDesign.getMaterialScene(primaryStage,root, 640, 480);
        MaterialDesign.setExitOnClose(true);
    
        MaterialEditableLayout layout=new  MaterialEditableLayout(false) {
            @Override
            public void onMenuButtonPressed(Button button) {
                new MaterialToast("I'm a toast!").unhide();

            }
        };
        layout.setTitle("Material JavaFX");

        root.getChildren().add(layout);

        primaryStage.setTitle("Material Showcase");
        primaryStage.show();
    }

And I get this:

View attachment 52798

The toast appears when you click on the menu button, right next to the title in the action bar.

Commented code is in the first comment. It looked so red for my taste.

Please, comment, is it alright when it comes to Material Design? Any flaw on how it looks?
  • Like
Reactions: 4 people

Comments

Here's the commented code. It looked too ugly in the OP, I like it cleaner when showing it.

Code:
@Override
    public void start(Stage primaryStage) {
        //A StackPane as root for the Scene
        StackPane root=new StackPane();
        /***This method applies the needed styles to the Stage and creates the needed Scene object.
        It returns the created Scene object, so you can assign it to a variable if you need to do something
        else with it. It receives the Stage, a Pane object which will act as root layout, and the wished width and height***/
        MaterialDesign.getMaterialScene(primaryStage,root, 640, 480);
        //This sets the app to stop completely when a Close is requested, like when you press the default Exit button
        MaterialDesign.setExitOnClose(true);
    
        /***A MaterialEditableLayout is a generic Material Layout which contains a Status Bar with the
        actual time, an Action Bar with a title and Menu Button, and the space where you will be able to add
        more elements***/
        MaterialEditableLayout layout=new  MaterialEditableLayout(false) {
            //Specify in this method what you want to happen when you click the Menu button.
            @Override
            public void onMenuButtonPressed(Button button) {
                //A MaterialToast object is used for notifications, or whenever you want to display a Popup message to the user.
                new MaterialToast("I'm a toast!").unhide();
            }
        };
        //This sets the text in the Action Bar
        layout.setTitle("Material JavaFX");

        //This adds the layout object to the Scene's root Pane object.
        root.getChildren().add(layout);

        //Finally, we set the title to the stage, which is the Window title, and show it. These are JavaFX Stage methods.
        primaryStage.setTitle("Material Showcase");
        primaryStage.show();
    }
 
Also, if you click on the "clock" label, you get a nice calendar on screen. However, it's only on Spanish right now. I'm adding the English language for next commit.
 
I don't know much about JavaFX or Material Design, but at least from how you create the window here, it looks straight-forward enough.

I can't really comment much on how it looks, since, believe it or not, I don't own(and therefore don't use) a smartphone(any other mobile phone for that matter).
It was a bit confusing to work with when I first tried your FireEditor, but I got used to it quite quickly.

Since you mentioned a commit, do you have a repository for this library?
 

Blog entry information

Author
Olmectron
Views
384
Comments
8
Last update

More entries in Personal Blogs

More entries from Olmectron