2010-04-06 13 views
1

我試圖創建一個分爲三個部分的窗口。不可調整大小的頁眉和頁腳,然後展開一個內容區域以填充窗口中的其餘區域。要開始,我創建了以下類:JFace ApplicationWindow:createContents不起作用

public class MyWindow extends ApplicationWindow { 
    Color white; 
    Font mainFont; 
    Font headerFont; 

    public MyWindow() { 
     super(null); 
     } 

    protected Control createContents(Composite parent) { 
     Display currentDisplay = Display.getCurrent(); 
     white = new Color(currentDisplay, 255, 255, 255); 
     mainFont = new Font(currentDisplay, "Tahoma", 8, 0); 
     headerFont = new Font(currentDisplay, "Tahoma", 16, 0); 

     // Main layout Composites and overall FillLayout 
     Composite container = new Composite(parent, SWT.NO_RADIO_GROUP); 
     Composite header = new Composite(container, SWT.NO_RADIO_GROUP); 
     Composite mainContents = new Composite(container, SWT.NO_RADIO_GROUP);; 
     Composite footer = new Composite(container, SWT.NO_RADIO_GROUP);; 
     FillLayout containerLayout = new FillLayout(SWT.VERTICAL); 
     container.setLayout(containerLayout); 

     // Header 
     Label headerLabel = new Label(header, SWT.LEFT); 
     headerLabel.setText("Header"); 
     headerLabel.setFont(headerFont); 

     // Main contents 
     Label contentsLabel = new Label(mainContents, SWT.CENTER); 
     contentsLabel.setText("Main Content Here"); 
     contentsLabel.setFont(mainFont); 

     // Footer 
     Label footerLabel = new Label(footer, SWT.CENTER); 
     footerLabel.setText("Footer Here"); 
     footerLabel.setFont(mainFont); 

     return container; 
    } 

    public void dispose() { 
     cleanUp(); 
    } 

    @Override 
    protected void finalize() throws Throwable { 
     cleanUp(); 
     super.finalize(); 
    } 

    private void cleanUp() { 
     if (headerFont != null) { 
      headerFont.dispose(); 
     } 
     if (mainFont != null) { 
      mainFont.dispose(); 
     } 
     if (white != null) { 
      white.dispose(); 
     } 
    } 
} 

,這導致一個空的窗口,當我運行它是這樣的:

public static void main(String[] args) { 
    MyWindow myWindow = new MyWindow(); 
    myWindow.setBlockOnOpen(true); 
    myWindow.open(); 
    Display.getCurrent().dispose(); 
} 

什麼我做錯了,我沒有看到三標記我試圖展示他們的方式? createContents代碼肯定是被調用的,我可以在Eclipse中以調試模式瀏覽它。

回答

0

顯然,我需要設置標籤的大小和位置以使它們出現。