使用工具栏搜索功能时,我遇到两个问题。
第一个(美学上的)问题是,进入或退出搜索模式时,工具栏消失了片刻,导致屏幕闪烁。
第二个(功能性)问题是,与侧面菜单一起,指针拖动事件在Toolbar.java的1302行的actionPerformed方法中导致NullPointerException。结果,在搜索模式下无法滚动。
这两个问题都可以使用下面的表格在模拟器和Android上复制。
亲切的问候,弗兰斯。
import com.codename1.ui.FontImage;
import com.codename1.ui.Form;
import com.codename1.ui.TextArea;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.layouts.BorderLayout;
public class ToolbarSearchForm extends Form
{
public ToolbarSearchForm()
{
super("Toolbar search", new BorderLayout());
getToolbar().addSearchCommand(e -> filter((String)e.getSource()));
getToolbar().addMaterialCommandToSideMenu("Settings", FontImage.MATERIAL_SETTINGS, this::settingsAction);
TextArea text = new TextArea(100, 100);
text.getAllStyles().setFgColor(0xFF000000);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++)
{
sb.append(i + " Hello World!\n");
}
text.setText(sb.toString());
add(BorderLayout.CENTER, text);
}
private void filter(String filter)
{
System.out.println(filter);
}
private void settingsAction(ActionEvent e)
{
System.out.println(e);
}
}
完整的堆栈跟踪为:
java.lang.NullPointerException
at com.codename1.ui.Toolbar$4.actionPerformed(Toolbar.java:1302)
at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:459)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:362)
at com.codename1.ui.Form.pointerDragged(Form.java:3146)
at com.codename1.ui.Display.handleEvent(Display.java:2118)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1051)
at com.codename1.ui.Display.mainEDTLoop(Display.java:969)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
java.lang.NullPointerException
at com.codename1.ui.Toolbar$4.actionPerformed(Toolbar.java:1302)
at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:459)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:362)
at com.codename1.ui.Form.pointerDragged(Form.java:3146)
at com.codename1.ui.Display.handleEvent(Display.java:2118)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1051)
at com.codename1.ui.Display.flushEdt(Display.java:826)
at com.codename1.ui.Form.showModal(Form.java:2098)
at com.codename1.ui.Dialog.showModal(Dialog.java:1137)
at com.codename1.ui.Dialog.show(Dialog.java:582)
at com.codename1.ui.Dialog.showPackedImpl(Dialog.java:1433)
at com.codename1.ui.Dialog.showPacked(Dialog.java:1349)
at com.codename1.ui.Dialog.showImpl(Dialog.java:1093)
at com.codename1.ui.Dialog.show(Dialog.java:1071)
at com.codename1.ui.Dialog.show(Dialog.java:1027)
at com.codename1.ui.Dialog.show(Dialog.java:793)
at com.codename1.ui.Dialog.show(Dialog.java:746)
at com.codename1.ui.Dialog.show(Dialog.java:711)
at com.codename1.ui.Dialog.show(Dialog.java:652)
at com.codename1.ui.Dialog.show(Dialog.java:807)
at com.codename1.ui.Display.mainEDTLoop(Display.java:982)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
getComponentForm()在此Toolbar.java行中返回null(因为工具栏没有父级):if (Display.getInstance().getImplementation().isScrollWheeling() || !enableSideMenuSwipe || getComponentForm().findCurrentlyEditingComponent() != null || getComponentForm().isEditing()) {