我正在尝试从MenuBar替换DockLayoutPanel的中心部分的内容。MenuBar将位于北部,但“内容”(表单、报表等)将位于中心。
我想我可以通过从RootPanel (索引为0,因为这是唯一直接连接到它的小部件)中抓取整个中心,然后以某种方式删除当前的DockLayoutPanel内容并插入新的内容。不幸的是,getWidget(int index)是非静态的,所以它不能工作。
有没有人能帮我找到正确的方法呢?不起作用的代码如下:
// snipped package and import details
public class menubar extends Composite {
private static menubarUiBinder uiBinder = GWT.create(menubarUiBinder.class);
interface menubarUiBinder extends UiBinder<Widget, menubar> {
}
@UiField MenuBar applicationMenuBar;
@UiField MenuBar processMenuBar;
@UiField MenuBar reportsMenuBar;
@UiField MenuItem addPowerRequirementCmd;
@UiField MenuItem powerUsageReportCmd;
public menubar() {
initWidget(uiBinder.createAndBindUi(this));
// command to replace whatever is in DockLayoutPanel.CENTER w/ AddPowerRequirement
// FormPanel
addPowerRequirementCmd.setCommand(new Command() {
@Override
public void execute() {
// get DockLayoutPanel from the RootPanel (it's the only widget, should be
// index 0
DockLayoutPanel dlp = (DockLayoutPanel) RootPanel.getWidget(0);
// clear out DockLayoutPanel.CENTER
// insert the FormLayoutPanel into DockLayoutPanel.CENTER
dlp.add(new PowerRequirementForm());
}
});
// command to replace whatever is in DockLayoutPanel.CENTER w/ power usage report
powerUsageReportCmd.setCommand(new Command() {
@Override
public void execute() {
}
});
}}
谢谢!
发布于 2011-02-05 04:45:28
使用ui:field属性,就像对MenuBar所做的那样,从UiBinder获取对DockLayoutPanel的引用:
<g:DockLayoutPanel ui:field="dockPanel"/>在课堂上:
@UiField DockLayoutPanel dockPanel;但是,根据应用程序状态,您似乎希望拥有一组显示在面板中心的小部件。DeckPanel是一种更好的解决方案:
<g:DockLayoutPanel>
<g:center>
<g:DeckPanel ui:field="deck">
<g:FlowPanel>Panel #0</g:FlowPanel>
<g:FlowPanel>Panel #1</g:FlowPanel>
</g:DeckPanel>
</g:center>
</g:DockLayoutPanel>然后切换DeckPanel的显示子项:
deck.showWidget(1); // Show Panel #1
deck.showWidget(0); // Show panel #0https://stackoverflow.com/questions/4901938
复制相似问题