-1

I am trying to add a Bottom Navigation to my Gluon Mobile app, so I was looking around and found this: How to create Bottom Navigation. I tried to implement this into my code, but it didn't work, so I transferred it to an empty, single-view project. There, I was able to identify the specific error after some troubleshooting and importing of packages. It is the following (the code with two asterisks surrounding it is the code producing the error and following is the error):

BottomNavigationButton btn1 = bottomNavigation.**createButton**("View1", MaterialDesignIcon.DASHBOARD.graphic(), e -> showView("view1"));
BottomNavigationButton btn2 = bottomNavigation.**createButton**("View2", MaterialDesignIcon.AC_UNIT.graphic(), e -> showView("view2"));
BottomNavigationButton btn3 = bottomNavigation.**createButton**("View3", MaterialDesignIcon.MAP.graphic(), e -> showView("view3"));

error for each line: cannot find symbol symbol: method createButton(String,Node,(e)->showV[...]ew2")) location: variable bottomNavigation of type BottomNavigation

Here is the entire code:

package com.myfirstapplication;

import com.gluonhq.charm.glisten.application.MobileApplication;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.BottomNavigation;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import com.gluonhq.charm.glisten.visual.Swatch;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class MyFirstApplication extends MobileApplication {

@Override
public void init() {

    addViewFactory(HOME_VIEW, () ->
    {

        StackPane root = new StackPane();
        root.getChildren().add(new Label("test"));

        View view = new View(root) {

            @Override
            protected void updateAppBar(AppBar appBar) {
                appBar.setTitleText("Home");
            }

        };
        view.setBottom(createBottomNavigation());
        return view;
    });

}

private BottomNavigation createBottomNavigation() {
    BottomNavigation bottomNavigation = new BottomNavigation();

    BottomNavigationButton btn1 = bottomNavigation.createButton("View1", MaterialDesignIcon.DASHBOARD.graphic(), e -> showView("view1"));
BottomNavigationButton btn2 = bottomNavigation.createButton("View2", MaterialDesignIcon.AC_UNIT.graphic(), e -> showView("view2"));
BottomNavigationButton btn3 = bottomNavigation.createButton("View3", MaterialDesignIcon.MAP.graphic(), e -> showView("view3"));


    bottomNavigation.getActionItems().addAll(btn1, btn2, btn3);

    return bottomNavigation;
}

private void showView(String viewName) {
    MobileApplication.getInstance().switchView(viewName);
}
}

1 Answers1

1

You should always look at JavaDoc first. Take a look at the documentation of CreateButton method. This method was deprecated and subsequently removed. Depreciation message describes precisely what you have to use instead.

Just to reiterate, don't start searching the internet for answers before looking at the documentation. The good starting place for it is at https://docs.gluonhq.com/ The latest JavaDoc for Glisten framework (mobile UI) is at https://docs.gluonhq.com/charm/javadoc/6.0.6/com.gluonhq.charm.glisten/module-summary.html

Eugene Ryzhikov
  • 17,131
  • 3
  • 38
  • 60
  • Ok, I apologize. However, I'm still unsure on how to use the buttons. I did read the documentation for BottomNavigationButton and tried to code an example, but I'm not used to using JavaDocs so I am a bit confused. It also says I need to use toggleButton with it, which I am unsure of how to do. If there is an example you could share I would greatly appreciate it. Thank you! –  Apr 21 '21 at 21:49