滑动另一个容器时不需要的向左滑动可滑动容器
Unwanted swipe left on swipeable container when swiping another
我在页面中添加了一些可滑动的容器。可滑动的容器有左右按钮,顶部组件是一个多按钮,可将用户带到另一个页面。当用户返回带有可滑动容器的页面并在不同的可滑动容器上向左(仅向左)滑动时,第一个容器也会向左打开。图片和示例代码如下:-
//Swipeable containers bugs
public void SwipeableContainerPage(Form mainForm){
Form formSC = new Form("Swipeable Container", new BorderLayout());
formSC.getToolbar().setBackCommand("", e -> mainForm.showBack());
Container northcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container centercnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container southcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
MultiButton mb_1 = new MultiButton("MB1");
Button b_l1 = new Button("LB1");
Button b_r1 = new Button("RB1");
MultiButton mb_2 = new MultiButton("MB2");
Button b_l2 = new Button("LB2");
Button b_r2 = new Button("RB2");
MultiButton mb_3 = new MultiButton("MB3");
Button b_l3 = new Button("LB3");
Button b_r3 = new Button("RB3");
SwipeableContainer sc_1 = new SwipeableContainer(b_l1, b_r1, mb_1);
SwipeableContainer sc_2 = new SwipeableContainer(b_l2, b_r2, mb_2);
SwipeableContainer sc_3 = new SwipeableContainer(b_l3, b_r3, mb_3);
mb_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GoToAndBackPage(formSC);
}
});
mb_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GoToAndBackPage(formSC);
}
});
mb_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GoToAndBackPage(formSC);
}
});
centercnt.add(sc_1);
centercnt.add(sc_2);
centercnt.add(sc_3);
formSC.add(BorderLayout.NORTH, northcnt).add(BorderLayout.CENTER, centercnt).add(BorderLayout.SOUTH, southcnt);
formSC.show();
}
//page for SC to go to
public void GoToAndBackPage(Form mainForm){
Form formGoTo = new Form("Go To Page", new BorderLayout());
formGoTo.getToolbar().setBackCommand("", e -> mainForm.showBack());
Container northcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container centercnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container southcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label l_welcome = new Label("Welcome to the Go To Page");
centercnt.add(l_welcome);
formGoTo.add(BorderLayout.NORTH, northcnt).add(BorderLayout.CENTER, centercnt).add(BorderLayout.SOUTH, southcnt);
formGoTo.show();
}
这听起来像是一个错误,理想情况下,您应该 file an issue 使用测试用例。但试试这个解决方法。
将处理导航的代码包装到串行调用中的不同表单中。例如。如果代码如下所示:
myMultiButton.addActionListener(e -> showOtherForm(...));
然后这样做:
myMultiButton.addActionListener(e -> callSerially(showOtherForm(...)));
我的理论是按压将可滑动组件带到“可能”被拖动的状态。但是因为导航事件恰好很快按钮没有收到释放事件(我们现在处于不同的形式)并且一切都丢失了。
因此,当您返回表单时,您现在有两个“收费”按钮。通过使用 callSerially
,您可以有效地刷新事件队列,并确保在移动到下一个 Form
.
之前,当前 Form
上的每个人都处理了释放事件
我在页面中添加了一些可滑动的容器。可滑动的容器有左右按钮,顶部组件是一个多按钮,可将用户带到另一个页面。当用户返回带有可滑动容器的页面并在不同的可滑动容器上向左(仅向左)滑动时,第一个容器也会向左打开。图片和示例代码如下:-
//Swipeable containers bugs
public void SwipeableContainerPage(Form mainForm){
Form formSC = new Form("Swipeable Container", new BorderLayout());
formSC.getToolbar().setBackCommand("", e -> mainForm.showBack());
Container northcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container centercnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container southcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
MultiButton mb_1 = new MultiButton("MB1");
Button b_l1 = new Button("LB1");
Button b_r1 = new Button("RB1");
MultiButton mb_2 = new MultiButton("MB2");
Button b_l2 = new Button("LB2");
Button b_r2 = new Button("RB2");
MultiButton mb_3 = new MultiButton("MB3");
Button b_l3 = new Button("LB3");
Button b_r3 = new Button("RB3");
SwipeableContainer sc_1 = new SwipeableContainer(b_l1, b_r1, mb_1);
SwipeableContainer sc_2 = new SwipeableContainer(b_l2, b_r2, mb_2);
SwipeableContainer sc_3 = new SwipeableContainer(b_l3, b_r3, mb_3);
mb_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GoToAndBackPage(formSC);
}
});
mb_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GoToAndBackPage(formSC);
}
});
mb_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GoToAndBackPage(formSC);
}
});
centercnt.add(sc_1);
centercnt.add(sc_2);
centercnt.add(sc_3);
formSC.add(BorderLayout.NORTH, northcnt).add(BorderLayout.CENTER, centercnt).add(BorderLayout.SOUTH, southcnt);
formSC.show();
}
//page for SC to go to
public void GoToAndBackPage(Form mainForm){
Form formGoTo = new Form("Go To Page", new BorderLayout());
formGoTo.getToolbar().setBackCommand("", e -> mainForm.showBack());
Container northcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container centercnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container southcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label l_welcome = new Label("Welcome to the Go To Page");
centercnt.add(l_welcome);
formGoTo.add(BorderLayout.NORTH, northcnt).add(BorderLayout.CENTER, centercnt).add(BorderLayout.SOUTH, southcnt);
formGoTo.show();
}
这听起来像是一个错误,理想情况下,您应该 file an issue 使用测试用例。但试试这个解决方法。
将处理导航的代码包装到串行调用中的不同表单中。例如。如果代码如下所示:
myMultiButton.addActionListener(e -> showOtherForm(...));
然后这样做:
myMultiButton.addActionListener(e -> callSerially(showOtherForm(...)));
我的理论是按压将可滑动组件带到“可能”被拖动的状态。但是因为导航事件恰好很快按钮没有收到释放事件(我们现在处于不同的形式)并且一切都丢失了。
因此,当您返回表单时,您现在有两个“收费”按钮。通过使用 callSerially
,您可以有效地刷新事件队列,并确保在移动到下一个 Form
.
Form
上的每个人都处理了释放事件