2012-03-08 50 views

回答

0

這將工作的唯一方法是正確處理繪製和調整大小。所以這是我工作的解決方案:

private void generateDetailsListGridHeader() { 
    createControls(); 
    section = new SectionStackSection(); 
    section.setCanCollapse(false); 
    section.setExpanded(true); 
    section.setControls(controls); 
    section.setItems(detailsListGrid); 

    sectionStack = new SectionStack(); 
    sectionStack.setSections(section); 
    sectionStack.addResizedHandler(new ResizedHandler() { 

     @Override 
     public void onResized(ResizedEvent event) { 
      htmlFlow.setWidth(sectionStack.getWidth() >> 1); 
      controls.setWidth(sectionStack.getWidth() - 10); 
     } 
    }); 
    sectionStack.addDrawHandler(new DrawHandler() { 

     @Override 
     public void onDraw(DrawEvent event) { 
      htmlFlow.setWidth(sectionStack.getWidth() >> 1); 
      controls.setWidth(sectionStack.getWidth() - 10); 
     } 
    }); 
} 

private void createControls() { 
    String title = "<table> <tr> <td style=\"vertical-align:middle; color:blue; font-size:15px\"> <b>Please double click a class from the left to display its instances</b> </td> </tr> </table>"; 
    controls = new HLayout(10); 
    htmlFlow = new HTMLFlow(title); 
    htmlFlow.setOverflow(Overflow.AUTO); 
    DynamicForm form = new DynamicForm(); 
    TextItem versionSearchItem = new TextItem("version", "Version"); 
    form.setItems(versionSearchItem); 
    controls.addMember(htmlFlow); 
    controls.addMember(form); 
} 

通過改變onResized和的onDraw裏面的寬度,你可以把任何你想要的每一個控制!

1

您可以使用一個HLayout作爲您的控件畫布。 HLayout可以擁有您想要設置的控件作爲其成員,但是現在您可以控制其在HLayout中的對齊,從而控制SectionStackSection。下面你可以看到一個簡單的例子:

SectionStack sectionStack = new SectionStack(); 
    sectionStack.setWidth(500); 
    sectionStack.setHeight(200); 

    SectionStackSection sectionStackSection = new SectionStackSection("Test"); 
    HLayout controls = new HLayout(); 
    controls.setWidth(sectionStack.getWidth()*8/10); 
    controls.setHeight(5); 

    controls.setLayoutAlign(Alignment.LEFT); 
    controls.setLayoutAlign(VerticalAlignment.CENTER); 

    IButton iButton = new IButton("C"); 
    iButton.setAutoFit(Boolean.TRUE); 
    iButton.setLayoutAlign(Alignment.LEFT); 

    controls.addMember(iButton); 

    sectionStackSection.setControls(controls); 
    sectionStack.addSection(sectionStackSection); 

使用HLayout的寬度進行微觀管理哪兒你的控制將顯現,SectionStackSection頭內。這不是一個完美的解決方案,但可以在簡單的情況下工作。

+0

答案中有一些正確的東西。但問題是,在繪製sectionStack之前使用'sectionStack.getWidth()',因此它會返回一個'null'值並導致錯誤。這是因爲我不想設置SectionStack的寬度,我希望它是自動的 – 2012-03-09 09:14:16

+0

它在生產代碼中沒有這個問題,但只在開發模式下。我想告訴你的想法是使用一個Canvas,其寬度足以讓你使用setAling方法。您的解決方案當然更完整,並在重繪/調整大小時自動處理事情。 – gpapaz 2012-03-09 10:30:56

+0

是的,大多數時候不要忘記小部件坐在其他小部件內部。不建議手動設置寬度,因爲它可能會產生問題,特別是在自動調整大小時。 – 2012-03-09 11:08:56

相關問題