我正在使用Viewport的Border layout进行我的应用程序。
现在我需要将整个Viewport添加到Accordion Layout中,我尝试通过创建Accordion面板然后创建另一个布局为FitLayout的内容面板来实现。在这个新创建的面板中添加了Viewport,最后将此面板添加到我的主手风琴面板
相应的代码是:
viewport = new Viewport();
viewport.setLayout(new BorderLayout());
menuBar = new ArmMenuBar();
createNorth();
createWest();
createEast();
createCenter();
createSouth();
//Added for Accordion Layout.
ContentPanel panel = new ContentPanel();
panel.setHeading("AccordionLayout");
panel.setBodyBorder(false);
panel.setLayout(new AccordionLayout());
ContentPanel cp = new ContentPanel();
cp.setAnimCollapse(false);
cp.setHeading("Portfolios Tab");
cp.setLayout(new FitLayout());
// registry serves as a global context
Registry.register(ClientConstant.VIEWPORT, viewport);
Registry.register(ClientConstant.ROOT_WEST_PANEL, west);
Registry.register(ClientConstant.ROOT_CENTER_PANEL, center);
Registry.register(ClientConstant.ROOT_EAST_PANEL, east);
// Registry.register(ClientConstant.ROOT_SOUTH_PANEL, south);
RootPanel.get().add(viewport);
KeyNav<ComponentEvent> key = new KeyNav<ComponentEvent>(viewport);
key.addKeyNavListener(new KeyNavListener() {
@Override
public void onEnter(ComponentEvent ce) {
System.out.println("");
}
});
//Added for Accordion Layout.
cp.add(viewport);
panel.add(cp);
但是我从给定的行
中得到了类强制转换的错误((BorderLayout) viewport.getLayout()).hide(LayoutRegion.WEST);
所以有人可以帮助我。
答案 0 :(得分:1)
未正确将Viewport添加到任何窗口小部件中...您必须在一个页面上使用一个视口。