如何将组件放在另一个组件的前面?

时间:2012-01-06 13:09:11

标签: java-me lwuit lwuit-form

我想将组件A和B放在带有List的组件上。我需要那个列表的文本将是可见的。我找不到哪种布局可以做到。 这种行为在lwuit中如何?有哪些解决方案?

enter image description here

2 个答案:

答案 0 :(得分:4)

问题有点不清楚,如果你想让组件的A和B驻留在屏幕的底部并且列表在上面滚动,那么jmunoz的答案是正确的。但是从图中看来,您可能希望通过玻璃窗格(对于非交互式组件)或通过LayeredLayout类实现“始终在线”效果。

使用以下内容实际上非常简单:

myForm.setLayout(new LayeredLayout());
myForm.setScrollable(false);

// will occupy the entire area of the form but should be scrollable
myForm.addComponent(componentUnderneath);
Container south = new Container(new BorderLayout());
myForm.addComponent(south);
south.addComponent(BorderLayout.SOUTH, whateverYouWantToPlaceOnTopInTheSouth);

答案 1 :(得分:1)

您必须执行以下操作:

Form不能滚动。使用Form.setScrollable(false)。将“形式”的布局设置为BORDER_LAYOUTmyForm.setLayout(new BorderLayout())。好的BorderLayout您可以根据需要将组件放在Form中。

使用ListBorderLayout组件放在myForm.addComponent(BorderLayout.CENTER, List)的中心,使用

将其他两个元素放在布局南边
Container southContainer = new Container();
southContainer.addComponent(A);
southContainer.addComponent(B);
myForm.addComponent(BorderLayout.SOUTH, southContainer)

通过这个,您可以获得一个可滚动的List,并且两个元素始终可见。

相关问题