Java 我在应用程序中添加侧菜单时遇到问题

Java 我在应用程序中添加侧菜单时遇到问题,java,codenameone,Java,Codenameone,当我使用代码添加侧菜单时,我不能告诉我您有问题,但我无法修复问题 可以帮助我修复代码或给我另一个代码 Form hi = new Form("Hi World"); Toolbar tb = hi.getToolbar(); Image icon = theme.getImage("mu.png"); Container topBar = BorderLayout.east(new Label()); topBar.add(BorderLayout.SOUTH, new Label("Cool

当我使用代码添加侧菜单时,我不能告诉我您有问题,但我无法修复问题

可以帮助我修复代码或给我另一个代码

Form hi = new Form("Hi World");
Toolbar tb = hi.getToolbar();
Image icon = theme.getImage("mu.png");
Container topBar = BorderLayout.east(new Label());
topBar.add(BorderLayout.SOUTH, new Label("Cool App
 Tagline...", "SidemenuTagline","));
topBar.setUIID("SideCommand");
tb.addComponentToSideMenu(topBar);
tb.addMaterialCommandToSideMenu("Home", FontImage.MATERIAL_HOME, e ->
 {});
tb.addMaterialCommandToSideMenu("Website", FontImage.MATERIAL_WEB, e ->
 {});
tb.addMaterialCommandToSideMenu("Settings", FontImage.MATERIAL_SETTINGS, e
 -> {});
tb.addMaterialCommandToSideMenu("About", FontImage.MATERIAL_INFO, e ->
 {});
hi.addComponent(new Label("Hi World"));
hi.show();

theme
是应该创建的资源文件。如果您在主类中,则创建主类后,
主题
变量应该已经存在。如果没有,您可以通过在代码之前添加此行在方法体中创建它:

Resources theme = getGlobalResources();
请注意,您需要使用设计器工具或CSS将图像
mu
显式添加到res文件中

我还注意到您对该代码有后续问题:

topBar.add(BorderLayout.SOUTH, new Label("Cool App
 Tagline...", "SidemenuTagline","));
在爪哇中,不能在中间断开一个字符串,如果要添加换行符,则需要使用<代码> \n>代码>:

topBar.add(BorderLayout.SOUTH, new Label("Cool App\nTagline...", "SidemenuTagline","));

theme
是应该创建的资源文件。如果您在主类中,则创建主类后,
主题
变量应该已经存在。如果没有,您可以通过在代码之前添加此行在方法体中创建它:

Resources theme = getGlobalResources();
请注意,您需要使用设计器工具或CSS将图像
mu
显式添加到res文件中

我还注意到您对该代码有后续问题:

topBar.add(BorderLayout.SOUTH, new Label("Cool App
 Tagline...", "SidemenuTagline","));
在爪哇中,不能在中间断开一个字符串,如果要添加换行符,则需要使用<代码> \n>代码>:

topBar.add(BorderLayout.SOUTH, new Label("Cool App\nTagline...", "SidemenuTagline","));