如何使ComponentGroup伸展以填充可用空间?
问题描述:
我想要ComponentGroup自动拉伸填充空间(例如表单的宽度)。我尝试了各种方法,例如将其封装在BoxLayout.y中,但尚未找到有效的方法。任何人都知道如何做到这一点?如何使ComponentGroup伸展以填充可用空间?
我想这是什么:
Form hiCG = new Form("ComponentGroup");
hiCG.add(BoxLayout.encloseY(ComponentGroup.encloseHorizontal(new Label("Text1"), new Label("Text22222"))));
//A hack to show what I'm after
Label label1 = new Label("Text3");
Label label2 = new Label("Text4444444");
label2.setPreferredW(hiCG.getWidth()/2); //using deprecated setPreferredW
ComponentGroup.setSameWidth(label1, label2);
hiCG.add(ComponentGroup.encloseHorizontal(label1, label2));
hiCG.show();
答
水平分量组可以滚动,以防止在过大,因此它不会成长屏幕失败的UI以适应尺寸。
我们可以添加一个适应它的网格布局,但现在这有点“硬编码”。解决方法可能是这样做:
Container c = GridLayout.encloseIn(2, label1, label2);
label1.setUIID("ToggleButtonFirst");
label2.setUIID("ToggleButtonLast");