如何使包含 SpanButton 的容器可拖动?
How to make a Container draggable even if it is containing a SpanButton?
在可拖动的容器中使用 SpanButton 似乎破坏了一些东西,因为容器不再能被拖动。即使使用 SpanButton,如何使 Container 仍可拖动?
我试图理解 CN1 代码,但对我来说很难理解。我的猜测是罪魁祸首是 SpanButton 使其内部 Button Lead 成为其自己的 Container,但我不明白为什么这会阻止包含 Container 在其级别上有另一个 Lead。
我还在下面的测试代码(第一个示例)中注意到,除非其中的某些(任意?)内容成为 Lead,否则设置 Container 可拖动是行不通的。不知道为什么,我没有在文档或此处找到任何解释。
Form hi = new Form("SpanButton ", BoxLayout.y());
{
Button button1 = new Button("Normal Button, no lead");
Container draggableContainer = BorderLayout.centerCenterEastWest(button1, new Button("Other"), null);
draggableContainer.setDraggable(true);
hi.add(draggableContainer);
//observation: container not draggable
}
{
Button button2 = new Button("Normal Button, lead");
Container draggableContainer = BorderLayout.centerCenterEastWest(button2, new Button("Other"), null);
draggableContainer.setDraggable(true);
draggableContainer.setLeadComponent(button2); //undocumented why a draggable Container doesn't work without a LeadComponent
hi.add(draggableContainer);
//observation: container draggable
}
{
SpanButton button3 = new SpanButton("SpanButton, lead");
Container draggableContainer = BorderLayout.centerCenterEastWest(button3, new Button("Other"), null);
draggableContainer.setDraggable(true);
draggableContainer.setLeadComponent(button3);
hi.add(draggableContainer);
//observation: container not draggable (well, "Other" can initiate a drag, but container disappears
}
hi.show();
我已将此测试用例添加到我们的样本中,并进行了一些修改,使其现在可以正常工作。
https://github.com/codenameone/CodenameOne/commit/37d12f8e749b258c7afb9fd66810a34153567b54
https://github.com/codenameone/CodenameOne/commit/261aeabc933d3020253d6ea552098e77bb32973d
这些将包含在明天的更新中。
在可拖动的容器中使用 SpanButton 似乎破坏了一些东西,因为容器不再能被拖动。即使使用 SpanButton,如何使 Container 仍可拖动?
我试图理解 CN1 代码,但对我来说很难理解。我的猜测是罪魁祸首是 SpanButton 使其内部 Button Lead 成为其自己的 Container,但我不明白为什么这会阻止包含 Container 在其级别上有另一个 Lead。
我还在下面的测试代码(第一个示例)中注意到,除非其中的某些(任意?)内容成为 Lead,否则设置 Container 可拖动是行不通的。不知道为什么,我没有在文档或此处找到任何解释。
Form hi = new Form("SpanButton ", BoxLayout.y());
{
Button button1 = new Button("Normal Button, no lead");
Container draggableContainer = BorderLayout.centerCenterEastWest(button1, new Button("Other"), null);
draggableContainer.setDraggable(true);
hi.add(draggableContainer);
//observation: container not draggable
}
{
Button button2 = new Button("Normal Button, lead");
Container draggableContainer = BorderLayout.centerCenterEastWest(button2, new Button("Other"), null);
draggableContainer.setDraggable(true);
draggableContainer.setLeadComponent(button2); //undocumented why a draggable Container doesn't work without a LeadComponent
hi.add(draggableContainer);
//observation: container draggable
}
{
SpanButton button3 = new SpanButton("SpanButton, lead");
Container draggableContainer = BorderLayout.centerCenterEastWest(button3, new Button("Other"), null);
draggableContainer.setDraggable(true);
draggableContainer.setLeadComponent(button3);
hi.add(draggableContainer);
//observation: container not draggable (well, "Other" can initiate a drag, but container disappears
}
hi.show();
我已将此测试用例添加到我们的样本中,并进行了一些修改,使其现在可以正常工作。 https://github.com/codenameone/CodenameOne/commit/37d12f8e749b258c7afb9fd66810a34153567b54 https://github.com/codenameone/CodenameOne/commit/261aeabc933d3020253d6ea552098e77bb32973d
这些将包含在明天的更新中。